具有多个嵌套和模型的模型的重复非嵌套的belongs_to关系

时间:2016-04-18 21:49:21

标签: ruby-on-rails amoeba-gem

如果标题不准确,我很难道歉,我很难将这个问题提炼成一行。我正在使用amoeba gem并尝试确定是否可以将重复模型与多个belongs_to关系相关联。

例如:

class Building < ActiveRecord::Base
  has_many    :floors
  has_many    :layout_groups
end

class Floor < ActiveRecord::Base
  belongs_to  :building
  has_many    :units
end

class Unit < ActiveRecord::Base
  belongs_to  :floor
  has_many    :layouts
end

class Layout < ActiveRecord::Base
  belongs_to :unit
  belongs_to :layout_group
end


class LayoutGroup < ActiveRecord::Base
  belongs_to  :building
  has_many    :layouts
end

如您所见,Layouts属于UnitLayoutGroup。如果我完全复制Building,如何将layoutsunitslayout_groups相关联,同时确保两组layouts在这个过程中没有创建?

我愿意使用非阿米巴溶液,我刚刚在那里提出建议。

0 个答案:

没有答案