2017-06-24 65 views
-1

這可能是一個相當直接的答案,我覺得我應該知道,但偶爾我遇到了這樣的事情,讓我感到困惑。構建關聯Rails 4

我正在開發一款Rails應用程序,它需要我基本上爲租賃創建一個租賃系統。

我有一個用戶,一個建築物,一個租約和一個單位。我現在得到它的結構的方式是:

class Buildings < ActiveRecord::Base 

    has_many :units 
    has_many :users 
end 

class User < ActiveRecord::Base 

    belongs_to :buildings 
    has_many :units, through :lease  
end 

class Lease < ActiveRecord::Base 

    belongs_to :user 
    belongs_to :unit 
end 

class Unit < ActiveRecord::Base 

    belongs_to :building 
    belongs_to :user 

    has_one :lease 
end 

我遇到了語法錯誤和關聯錯誤,並且文檔清晰如泥。也許有人可以幫助我正確地組織這些協會。

+0

你遵循哪些文件? – vee

+0

guides.rubyonrails.org/association_basics.html – PSCampbell

回答

-2

你的語法錯誤是User類

變化

has_many :units, through :lease 

has_many :unit, through: :lease 

has_many :units, :through => :lease 
+0

您的回答需要審查?等待OP的文檔! – vee