I have a type model that has_many :products and a product model that has_one :type.
The dynamic methods are working okay, but only if .product is called on an object that contains only one instance of type.
controller:
def index
@all = Type.all
@one = Type.find_by_id(2)
end
view:
<%= debug @one.products %> #=> Hash of products with the type_id of 2
So far so good, but then:
<%= debug @all.products %>
results in a no 'products method defined' error. I think I sort of know why. @all contains multiple ids, and rails can't work out that I want all of the product entries that contain those multiple foreign keys. It seems it can only manage querying automatically for one foreign key.
Should this be a many to many relationship? That doesn't make sense, because every product really does only have one type. But how can I query for multiple types concisely?
What is want to achieve is have all of the product entries on one page, product entries that belong to all of the type entries.