One-to-many
Use has_many
in the base and belongs_to
in the associated model:
class Category < ActiveRecord::Base has_many :products end class Product < ActiveRecord::Base belongs_to :category end
See Figure 2.
Figure 2. One-to-many associations
Get Rails Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.