我有以下模型及其关系:
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
Anaccount
拥有 a business
,并且 abusiness
有许多与之关联的客户。
在我的控制器中,设置客户实例后,我尝试执行以下操作:
@customer.business = @account.business
检查@customer.business
, 和@account.business
时,一切正常。但是,当我尝试做: 时@account.business.customers
,我总是得到一个空数组。