1
It is mandatory that in order to have an association between two models, I have belongs_to
and has_one
? Or it is possible to use only has_one/has_many
between the two models, when not necessarily any of the models belong to some other?
Example:
class Article < ActiveRecord::Base
has_one :category
end
class Category < ActiveRecord::Base
has_many :articles
end
You can better understand in the official guide: /Association Basics
– Danilo Cândido
@Danilocândido came up this reading precisely the Rails Guides :/ The Migration of the example for
has_one
for example corresponds tot.belongs_to :supplier
.– Luan Vicente