So, I have a STI organization that goes like this:
class Parent
end
class Son < Parent
end
class Daughter < Parent
end
But each child has a HBTM(has_and_belongs_to_many) relation with a different model. Let's call it Chick and Dude, so it would look like this:
class Parent
end
class Son < Parent
has_and_belongs_to_many :chicks
end
class Daughter < Parent
has_and_belongs_to_many :dudes
end
Where should I declare the relation-ships? Both at the Parent model? Does it need any additional options? Will Rails make the column null when it should be by it self?
I've been looking for an answer for this but couldn't find it, maybe because it is just too dumb.
EDIT
As mentioned by Peter Alfvin, HBTM relations must come along with an auxiliary join table. Which means that this configuration would require two join tables.
But, I did not find any documentation about the nomenclature that should be used in this very specific example.
The join table should include the name of the database table 'parents' or the model's name 'daughters'?
The same problem occur with the id column referencing the STI, should it be named after the database table or the model?
For what I could understand, it works like each of the STI sub classes had it's own table (although in the database they use the same, named after it's parent). So, in the HBTM join table, you should use ID and table name referent to the "illusionary" child table. The migration look's like this: