The rails app contains many different content pages. Pages are organized into small groups known as sections:
class Page < ActiveRecord::Base
attr_accessible: section_id
belongs_to :section
end
class Section < ActiveRecord::Base
attr_accessible :title
has_many :pages
end
Sections should also be organized, but what is the best way to do this - reuse the sections themselves or create a new Unit model?
Option 1 - Reuse Partition
Allow the partition to have child and parent sections. Thus, you do not need to create another model with similar fields, such as Section. Some sections will have several pages, while other sections will have several child sections:
class Section < ActiveRecord::Base
attr_accessible :parent_id :title
has_many :pages
belongs_to :parent, class_name: "Section"
has_many :children, class_name: "Section", foreign_key: "parent_id"
end
2 -
Unit . , .
class Section < ActiveRecord::Base
attr_accessible :title, :unit_id
has_many :pages
belongs_to :units
end
class Unit < ActiveRecord::Base
attr_accessible :title
has_many :sections
end
1 , , . , 2 , , , , . ?
, 2 , , . , ? , , :
2 - . , - .
1 - . , .