0
我有這個型號:HAS_MANY通過使用factoryGirl
class Application < ActiveRecord::Base
has_many :admin_user_applications, dependent: :destroy
has_many :admin_users, through: :admin_user_applications, :source => :user, validate: :false
end
class User < ActiveRecord::Base
has_many :admin_user_applications, dependent: :destroy
has_many :administrable_applications, through: :admin_user_applications, :source => :application
end
class UserApplication < ActiveRecord::Base
belongs_to :user
belongs_to :application
end
我定義我的應用程序廠:
FactoryGirl.define do
factory :application, :class => Application do
sequence(:name) {|n| "application-#{n}" }
association :owner, :factory => :user
end
end
但是當我這樣做:
app_3 = FactoryGirl.create(:application, admin_users: [@user])
puts @user.admin_user_applications.inspect # =>[]
返回我[ ]
做什麼我做錯了?
當然,它可以工作,但我試圖找到使用FactoryGirl做到這一點的方式 – Sebastien