Gary Weaver
2012-Sep-21 14:55 UTC
Good resource for the history of activerecord association method naming?
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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Gary Weaver
2012-Sep-21 20:05 UTC
Re: Good resource for the history of activerecord association method naming?
On Friday, September 21, 2012 10:55:38 AM UTC-4, Gary Weaver wrote:> > 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 >Sorry, to be clear I meant those are two different ways of specifying that an instance of a model''s attribute can have many of some other model instance. -- 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/-/KSe7oXDvW2IJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Godfrey Chan
2012-Sep-21 20:27 UTC
Re: Good resource for the history of activerecord association method naming?
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 rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Koziarski
2012-Sep-21 23:46 UTC
Re: Good resource for the history of activerecord association method naming?
> 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? >Basically all of those associations were present in rails before there even was a mailing list. You''d have to rummage around the git history to see if they were all done before there was any outside assistance, but I suspect the conversations you''re looking for were all in DHH''s head ;)> 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 rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Godfrey Chan
2012-Sep-21 23:48 UTC
Re: Good resource for the history of activerecord association method naming?
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 rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.