Forum: Ruby on Rails association problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
746685aedd7062af2c2b9115310e6d7d?d=identicon&s=25 Anmol Kumar (anmol591)
on 2017-04-30 10:44
What is the correct way to define one to many association in rails 5.we
have currently the following migration files...we have to define
products and categories tables such that one category has many products.

class Category < ApplicationRecord
  has_many :products, dependent: :destroy
end

class Product < ApplicationRecord
  belongs_to :category, index: true
end
This topic is locked and can not be replied to.