i’ve been looking at has_many and belongs_to
I understand it to be the case that if there is a 1—M between A----B then B points to A, and since B points to A, you put the belongs_to in the B class. and the has_many in the A class. So the class/model whose table will have the foreign key, gets the belongs_to line.
However… i’ve noticed that in the case of a M—M relationship,
so, where table A doesn’t point to table B, and table B doesn’t point to table A. But rails will generate a join table to link them. Yet even though both table A and table B don’t have foreign keys to each other, you still put has_and_belongs_to_many line, that goes in the model for A and the model for B. Even though neither has a foreign key to the other.
So what is the rule for when you write …belongs_to ?