2013-07-12 44 views
0

我與他們之間的關係如下模式:分配對象協會不工作

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,我總是得到一個空數組。

回答

0

我假設你在分配帳戶業務後保存了客戶?

+0

就是這樣!沒有線索這個問題。謝謝 – darksky

+0

是的,他們必須在某個時候被保存以獲得ID,這在協會中將被查詢。 – bmac151