<http://wiki.rubyonrails.org/rails/pages/ThroughAssociations> suggests,
essentially, using "baz" while I believe that I've seen sources
suggesting "foos_bars" and, I believe, "foo_bars". In particular, on
this list, joining tables "foos" and "bars" with a many-to-many,
"foos_bars" was recommended for the join table.
I always used foos_bars as a join table for a habtm association.
I don't get the 'baz' but i think it references when you have a many
to many relationship through something other than a join table?
with habtm, you have to use foos_bars. With has many :through, the
join table in a model in its own right and so you can call it anything
you want. When possible you should strive to find a 'proper' name for
the join model. For example if your app was a forum type application,
where users could subscribe to topics then a good name for the join
model between users and topics would be 'subscription'
I don't have it in front of me, but in the "rails recipes" book, one
of the recipes is for a habtm relationship. They have three tables,
foos, bars, and baz. They don't use "foos_bars" to my recollection.
That is, the name for the join table is unrelated to the name for
either table. However, that's based on my recollection that it's a
habtm relationship, but I think so.
I don't have it in front of me, but in the "rails recipes" book, one
of the recipes is for a habtm relationship. They have three tables,
foos, bars, and baz. They don't use "foos_bars" to my recollection.
That is, the name for the join table is unrelated to the name for
either table. However, that's based on my recollection that it's a
habtm relationship, but I think so.
from the api documentation:
"Unless the join table is explicitly specified as an option, it is
guessed using the lexical order of the class names. So a join between
Developer and Project will give the default join table name of
developers_project"
This is an out of date technique to set up the many-to-many table. A
major limitation to this method is that you cannot have any more fields
in the table then the 2 joining fields, and the join table does not use
a primary field key called 'id'. You can't sort joined fields very
easily with this method.
This makes it sound like HABTM is obsolete. It isn't if you don't
need to have attributes on the association, I think it serves
perfectly way.
This technique is very easy to set up. The table name is the plural
names of the 2 joining tables, in alphabetical order, separated by an
underscore. Table C and B would be BS_CS. The only 2 fields in the join
table would be b_id and c_id.
And if the too records were foo and bar, the join table would be
bars_foos, not foos_bars as has been mistakenly said at least once in
this thread.
On the other hand, the link in the original post was to a description
of :has_many :through and I think that the OP was confused between
examples of HABTM and HM T.
And if the too records were foo and bar, the join table would be
bars_foos, not foos_bars as has been mistakenly said at least once in
this thread.
What's the distinction between foos_bars and bars_foos please? A
many-to-
many isn't "directional", is it?
No, but you've got to pick something and by default hatbm would pick
bars_foos (My mistake for saying foos_bars earlier - Time to brush up
on my alphabet )