Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated documentation for associations #387 [canadaduane]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@299 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit cab24945634bc22b0c0c5d10b72c83eaa09f1e41 1 parent 3b05d41
@dhh dhh authored
Showing with 10 additions and 7 deletions.
  1. +10 −7 activerecord/lib/active_record/associations.rb
View
17 activerecord/lib/active_record/associations.rb
@@ -122,7 +122,7 @@ def clear_association_cache #:nodoc:
# All of the association macros can be specialized through options which makes more complex cases than the simple and guessable ones
# possible.
module ClassMethods
- # Adds the following methods for retrival and query of collections of associated objects.
+ # Adds the following methods for retrieval and query of collections of associated objects.
# +collection+ is replaced with the symbol passed as the first argument, so
# <tt>has_many :clients</tt> would add among others <tt>has_clients?</tt>.
# * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects.
@@ -224,7 +224,7 @@ def has_many(association_id, options = {})
deprecated_build_method(association_name)
end
- # Adds the following methods for retrival and query of a single associated object.
+ # Adds the following methods for retrieval and query of a single associated object.
# +association+ is replaced with the symbol passed as the first argument, so
# <tt>has_one :manager</tt> would add among others <tt>has_manager?</tt>.
# * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found.
@@ -280,7 +280,7 @@ def has_one(association_id, options = {})
module_eval "before_destroy '#{association_name}.destroy if has_#{association_name}?'" if options[:dependent]
end
- # Adds the following methods for retrival and query for a single associated object that this object holds an id to.
+ # Adds the following methods for retrieval and query for a single associated object that this object holds an id to.
# +association+ is replaced with the symbol passed as the first argument, so
# <tt>belongs_to :author</tt> would add among others <tt>has_author?</tt>.
# * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found.
@@ -289,7 +289,7 @@ def has_one(association_id, options = {})
# same id as the associated object.
# * <tt>association.nil?</tt> - returns true if there is no associated object.
#
- # Example: An Post class declares <tt>has_one :author</tt>, which will add:
+ # Example: A Post class declares <tt>has_one :author</tt>, which will add:
# * <tt>Post#author</tt> (similar to <tt>Author.find(author_id)</tt>)
# * <tt>Post#author=(author)</tt> (similar to <tt>post.author_id = author.id</tt>)
# * <tt>Post#author?</tt> (similar to <tt>post.author == some_author</tt>)
@@ -364,9 +364,12 @@ def belongs_to(association_id, options = {})
#
# Any additional fields added to the join table will be placed as attributes when pulling records out through
# has_and_belongs_to_many associations. This is helpful when have information about the association itself
- # that you want available on retrival.
+ # that you want available on retrieval. Note that any fields in the join table will override matching field names
+ # in the two joined tables. As a consequence, having an "id" field in the join table usually has the undesirable
+ # result of clobbering the "id" fields in either of the other two tables.
+ #
#
- # Adds the following methods for retrival and query.
+ # Adds the following methods for retrieval and query.
# +collection+ is replaced with the symbol passed as the first argument, so
# <tt>has_and_belongs_to_many :categories</tt> would add among others +add_categories+.
# * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects.
@@ -574,4 +577,4 @@ def require_association_class(class_name)
end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.