将对象分配给关联不起作用

时间:2013-07-12 22:13:43

标签: ruby-on-rails ruby activerecord associations

我的关系有以下模型:

class Account < ActiveRecord::Base
  has_one :business, :inverse_of => :account
end

class Business < ActiveRecord::Base
  belongs_to :account, :inverse_of => :business
  has_many :customers, :inverse_of => :business
end

class Customer < ActiveRecord::Base
  belongs_to :business, :inverse_of => :customers
end

account拥有businessbusiness有许多客户与之关联。

在我的控制器中,在设置客户实例后,我尝试执行以下操作:

@customer.business = @account.business

检查@customer.business@account.business时,一切正常。但是,当我尝试执行:@account.business.customers时,我总是得到一个空数组。

1 个答案:

答案 0 :(得分:0)

我假设您在分配了帐户业务后保存了客户?