Somehow this didn't go through the first time

----------

Several observations:

1. You're supposed to read them with the model name. So "a Post belongs_to an 
User" and "an User has_many Subscriptions". These two makes a lot of sense most 
of the time and reads very naturally, which seems consistent among the nicer 
part of Ruby/Rails syntax (an object.is_a? type, do xyz unless condition.)

2. Granted, has_and_belongs_to_many probably makes less sense if you look at 
that on its own. But given the two names we have above it is very easy to 
understand what this means. has_many is the "n" side of a 1-n, and belongs_to 
is the "1" side, so has_and_belongs_to_many naturally means the "n" side of 
n-n. And really, "a User has_and_belongs_to_many Groups" is not really so bad.

3. This has been around for as long as I could tell. It predates the first 
public commit on svn and the rails website. So it's quite likely that 
"discussions" doesn't even apply here as it probably existed when Rails is 
still DHH's pet project.

4. Naming is hard. It is one of those things where you just have to make some 
decision and then move on to other more important things in life.


On 2012-09-21, at 7:55 AM, Gary Weaver wrote:

> Someone asked me about the history of the method naming in activerecord and I 
> wasn't sure where to point them. For example, there was early criticism noted 
> of has_and_belongs_to_many in this old post from 2005:
> http://hans.fugal.net/blog/2005/10/03/habtm/
> 
> I was mentioning that many_to_many is not used because there are a few 
> different ways of doing that via has_many :through and 
> has_and_belongs_to_many, and to me belongs_to seems reasonable since it is a 
> model associated with a child table that has a foreign key to a parent table, 
> however that could have been foreign_key_to or similar to eliminate 
> confusion, I guess, though maybe that makes the name less flexible and more 
> tied to relational DB terms? Maybe having some aliases would make sense, I 
> don't know. I'm kind of used to it all now, but maybe there is some way it 
> could all be clearer.
> 
> Does anyone have links to discussions or pages where the history of 
> association naming was discussed for those that think it doesn't make any 
> sense and want a better explanation as to why associative methods are named 
> as they are? Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/rubyonrails-core/-/ay3rkyV5cVcJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-core?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to