belongs_to
Belongs to represents an association where the associated object share its primary key in a column of the current object. Let's give an example:
In this case, Post belongs to categories, as it maintain a link to the category through category_id
column.
In clear, this relation can be written like this:
Clear will take care for you of the declaration of the column
category_id
You may notice
has_many
in Category model. We will go further onto it in the next chapter.
Customizing the relation
Clear uses naming convention to infer the name of the foreign key. You may want to override this behavior by adding some parameters:
Last updated