【发布时间】:2017-06-24 01:38:11
【问题描述】:
这可能是一个我觉得我应该知道的相当直截了当的答案,但偶尔我会遇到这样的事情让我很困惑。
我正在开发一个 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
我遇到了语法错误和关联错误,并且文档清晰如泥。也许有人可以帮助我正确构建这些关联。
【问题讨论】:
-
您遵循了哪些文档?
-
guides.rubyonrails.org/association_basics.html
标签: ruby-on-rails associations