Answer the question
In order to leave comments, you need to log in
When should belongs_to be set, and when should has_one?
There is a Page model that is needed for a text page.
There is a Feature model that is needed for the icons on the main page. It may lead to some page, or it may not lead. You just need the page_id field, which can be null (it's already created by the migration).
The question is, should you do
class Feature < ApplicationRecord
has_one :page
end
class Feature < ApplicationRecord
belongs_to :page
end
Answer the question
In order to leave comments, you need to log in
belongs_to means the Page has many Features. Those. for feedback, the Page must have
class Page < ApplicationRecord
has_many :features
end
page = Page.first
page.features
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question