Please excuse the confusing phrasing in the title. In my RoR project let’s say I have it set up like this
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
and
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
I then have a categories_products table that connects them. This works fine but my problem is that a product will only ever have one category at a time and I’d of course like to do product.category instead of having to deal with an array. How can I accomplish that?
A one-to-many representation is demonstrated in the rails guides like this: