Matt, Thank you very much for this explanation!
I have actually read the official Rails documentation: Module ActiveRecord::Associations::ClassMethods a couple of times, and I did not find it mentioned anywhere the equivalent of: > there's a field owner_id on the model declaring the belongs_to Field names are not mentioned in the official documentation, or I missed it. The below is the closest thing to identifying the use of a field in an association, again from the official documentation: belongs_to :author, :class_name => "Person", :foreign_key => "author_id" >From the above I believe I can infer the symbol :author is being interpreted to the field 'author_id'. That still is not all that clear in my mind. If you have an overall understanding of the complete process it is sufficient. But for me the whole purpose of documentation is to provide a lucid description that stands on its own: you do not have to have a general knowledge in order to understand the documentation. So I feel the official Rails documentation should be improved also :) Anyway, your explanation has finally resolved this missing bit of information for me and I appreciate it. Cheers, Jet > > I have had difficulty with this a number of times ... > > belongs_to :owner, :class_name => "User" > There isn't an Owner class in this instance - that's what > the :class_name option tells Rails. The declaration above implies that > there's a field owner_id on the model declaring the belongs_to, and > that owner_id is a foreign key to the 'users' table (OK, technically a > foreign key to the table specified in User.table_name). > > I'd also recommend reading over the Rails docs for belongs_to and > friends - they are actually pretty helpful. > > --Matt Jones
-- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
