public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Improve readability of other ActiveRecord association methods' 
documentation.
Hongli Lai (Phusion) (author)
Sat Jul 19 03:05:16 -0700 2008
commit  038c7fdeea33d7aabc918b29304a262b663e3604
tree    b2853b94e45763daa69640d5a1217ef8bcb19714
parent  4d719c185ac17d30c624add296872111570bf5b6
...
73
74
75
 
76
77
78
...
639
640
641
642
 
643
644
645
 
646
647
648
649
 
650
651
652
653
654
 
655
656
657
...
769
770
771
772
773
774
775
776
 
 
 
 
 
 
 
 
 
 
 
777
778
779
780
781
782
783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
784
785
 
 
 
786
787
788
789
790
791
 
 
792
793
794
795
 
 
796
797
798
 
 
799
800
 
 
801
802
 
 
803
804
805
 
 
806
807
808
809
810
811
 
 
 
 
 
 
 
 
812
813
 
 
814
815
816
 
 
817
818
819
 
 
820
821
822
 
 
 
 
823
824
825
...
859
860
861
862
863
864
865
866
867
868
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
869
870
871
 
 
 
 
872
873
 
 
 
 
 
 
874
875
876
...
879
880
881
882
883
 
 
 
 
884
885
886
 
 
887
888
 
 
889
890
 
 
891
892
893
894
 
 
895
896
897
898
 
 
899
900
901
...
903
904
905
906
907
 
 
 
 
908
909
910
911
 
 
 
 
912
913
914
...
994
995
996
997
998
 
 
 
999
1000
1001
...
1010
1011
1012
1013
1014
1015
 
 
 
1016
1017
 
 
1018
1019
 
 
1020
1021
1022
1023
1024
1025
1026
1027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1028
1029
 
 
 
 
 
 
1030
1031
 
 
1032
1033
1034
 
 
 
 
 
 
1035
1036
1037
...
1042
1043
1044
 
1045
1046
1047
1048
1049
1050
 
 
 
 
1051
1052
1053
1054
1055
1056
 
 
 
 
 
 
1057
1058
1059
 
 
1060
1061
1062
 
 
1063
1064
1065
1066
 
 
1067
1068
1069
1070
 
 
 
 
 
 
1071
1072
 
 
1073
1074
1075
1076
1077
1078
1079
 
 
 
 
 
 
 
 
 
 
 
 
1080
1081
1082
 
 
 
 
1083
1084
1085
...
73
74
75
76
77
78
79
...
640
641
642
 
643
644
645
 
646
647
648
649
 
650
651
652
653
654
 
655
656
657
658
...
770
771
772
 
 
 
 
 
773
774
775
776
777
778
779
780
781
782
783
784
 
 
 
 
 
 
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
 
800
801
802
803
804
805
806
807
808
809
810
811
812
813
 
814
815
816
817
 
818
819
820
 
821
822
823
 
824
825
826
827
 
828
829
830
831
 
 
 
 
832
833
834
835
836
837
838
839
840
 
841
842
843
844
 
845
846
847
848
 
849
850
851
 
 
852
853
854
855
856
857
858
...
892
893
894
 
 
 
 
 
 
 
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
 
 
912
913
914
915
916
 
917
918
919
920
921
922
923
924
925
...
928
929
930
 
 
931
932
933
934
935
936
 
937
938
939
 
940
941
942
 
943
944
945
946
947
 
948
949
950
951
952
 
953
954
955
956
957
...
959
960
961
 
 
962
963
964
965
966
967
 
 
968
969
970
971
972
973
974
...
1054
1055
1056
 
 
1057
1058
1059
1060
1061
1062
...
1071
1072
1073
 
 
 
1074
1075
1076
1077
 
1078
1079
1080
 
1081
1082
1083
 
 
 
 
 
 
 
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
 
1099
1100
1101
1102
1103
1104
1105
 
1106
1107
1108
1109
 
1110
1111
1112
1113
1114
1115
1116
1117
1118
...
1123
1124
1125
1126
1127
1128
1129
1130
 
 
1131
1132
1133
1134
1135
1136
 
 
 
 
1137
1138
1139
1140
1141
1142
1143
1144
 
1145
1146
1147
1148
 
1149
1150
1151
1152
1153
 
1154
1155
1156
 
 
 
1157
1158
1159
1160
1161
1162
1163
 
1164
1165
1166
 
 
 
 
 
 
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
 
 
1180
1181
1182
1183
1184
1185
1186
0
@@ -73,6 +73,7 @@ module ActiveRecord
0
     end
0
   end
0
 
0
+ # See ActiveRecord::Associations::ClassMethods for documentation.
0
   module Associations # :nodoc:
0
     def self.included(base)
0
       base.extend(ClassMethods)
0
@@ -639,19 +640,19 @@ module ActiveRecord
0
       # [collection.size]
0
       # Returns the number of associated objects.
0
       # [collection.find(...)]
0
- # Finds an associated object according to the same rules as Base.find.
0
+ # Finds an associated object according to the same rules as ActiveRecord::Base.find.
0
       # [collection.exist?(...)]
0
       # Checks whether an associated object with the given conditions exists.
0
- # Uses the same rules as Base.exists?.
0
+ # Uses the same rules as ActiveRecord::Base.exists?.
0
       # [collection.build(attributes = {}, ...)]
0
       # Returns one or more new objects of the collection type that have been instantiated
0
       # with +attributes+ and linked to this object through a foreign key, but have not yet
0
- # been saved. *Note:* This only works if an associated object already exists, not if
0
+ # been saved. <b>Note:</b> This only works if an associated object already exists, not if
0
       # it's +nil+!
0
       # [collection.create(attributes = {})]
0
       # Returns a new object of the collection type that has been instantiated
0
       # with +attributes+, linked to this object through a foreign key, and that has already
0
- # been saved (if it passed the validation). *Note:* This only works if an associated
0
+ # been saved (if it passed the validation). <b>Note:</b> This only works if an associated
0
       # object already exists, not if it's +nil+!
0
       #
0
       # (*Note*: +collection+ is replaced with the symbol passed as the first argument, so
0
@@ -769,57 +770,89 @@ module ActiveRecord
0
         end
0
       end
0
 
0
- # Adds the following methods for retrieval and query of a single associated object:
0
- # +association+ is replaced with the symbol passed as the first argument, so
0
- # <tt>has_one :manager</tt> would add among others <tt>manager.nil?</tt>.
0
- # * <tt>association(force_reload = false)</tt> - Returns the associated object. +nil+ is returned if none is found.
0
- # * <tt>association=(associate)</tt> - Assigns the associate object, extracts the primary key, sets it as the foreign key,
0
+ # Specifies a one-to-one association with another class. This method should only be used
0
+ # if the other class contains the foreign key. If the current class contains the foreign key,
0
+ # then you should use +belongs_to+ instead. See also ActiveRecord::Associations::ClassMethods's overview
0
+ # on when to use has_one and when to use belongs_to.
0
+ #
0
+ # The following methods for retrieval and query of a single associated object will be added:
0
+ #
0
+ # [association(force_reload = false)]
0
+ # Returns the associated object. +nil+ is returned if none is found.
0
+ # [association=(associate)]
0
+ # Assigns the associate object, extracts the primary key, sets it as the foreign key,
0
       # and saves the associate object.
0
- # * <tt>association.nil?</tt> - Returns +true+ if there is no associated object.
0
- # * <tt>build_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated
0
- # with +attributes+ and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if
0
- # an association already exists. It will NOT work if the association is +nil+.
0
- # * <tt>create_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated
0
- # with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
0
+ # [association.nil?]
0
+ # Returns +true+ if there is no associated object.
0
+ # [build_association(attributes = {})]
0
+ # Returns a new object of the associated type that has been instantiated
0
+ # with +attributes+ and linked to this object through a foreign key, but has not
0
+ # yet been saved. <b>Note:</b> This ONLY works if an association already exists.
0
+ # It will NOT work if the association is +nil+.
0
+ # [create_association(attributes = {})]
0
+ # Returns a new object of the associated type that has been instantiated
0
+ # with +attributes+, linked to this object through a foreign key, and that
0
+ # has already been saved (if it passed the validation).
0
+ #
0
+ # (+association+ is replaced with the symbol passed as the first argument, so
0
+ # <tt>has_one :manager</tt> would add among others <tt>manager.nil?</tt>.)
0
       #
0
- # Example: An Account class declares <tt>has_one :beneficiary</tt>, which will add:
0
+ # === Example
0
+ #
0
+ # An Account class declares <tt>has_one :beneficiary</tt>, which will add:
0
       # * <tt>Account#beneficiary</tt> (similar to <tt>Beneficiary.find(:first, :conditions => "account_id = #{id}")</tt>)
0
       # * <tt>Account#beneficiary=(beneficiary)</tt> (similar to <tt>beneficiary.account_id = account.id; beneficiary.save</tt>)
0
       # * <tt>Account#beneficiary.nil?</tt>
0
       # * <tt>Account#build_beneficiary</tt> (similar to <tt>Beneficiary.new("account_id" => id)</tt>)
0
       # * <tt>Account#create_beneficiary</tt> (similar to <tt>b = Beneficiary.new("account_id" => id); b.save; b</tt>)
0
       #
0
+ # === Options
0
+ #
0
       # The declaration can also include an options hash to specialize the behavior of the association.
0
       #
0
       # Options are:
0
- # * <tt>:class_name</tt> - Specify the class name of the association. Use it only if that name can't be inferred
0
+ # [:class_name]
0
+ # Specify the class name of the association. Use it only if that name can't be inferred
0
       # from the association name. So <tt>has_one :manager</tt> will by default be linked to the Manager class, but
0
       # if the real class name is Person, you'll have to specify it with this option.
0
- # * <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
+ # [:conditions]
0
+ # Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
       # SQL fragment, such as <tt>rank = 5</tt>.
0
- # * <tt>:order</tt> - Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
0
+ # [:order]
0
+ # Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
0
       # such as <tt>last_name, first_name DESC</tt>.
0
- # * <tt>:dependent</tt> - If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
0
+ # [:dependent]
0
+ # If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
0
       # <tt>:delete</tt>, the associated object is deleted *without* calling its destroy method. If set to <tt>:nullify</tt>, the associated
0
       # object's foreign key is set to +NULL+. Also, association is assigned.
0
- # * <tt>:foreign_key</tt> - Specify the foreign key used for the association. By default this is guessed to be the name
0
+ # [:foreign_key]
0
+ # Specify the foreign key used for the association. By default this is guessed to be the name
0
       # of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_one+ association will use "person_id"
0
       # as the default <tt>:foreign_key</tt>.
0
- # * <tt>:primary_key</tt> - Specify the method that returns the primary key used for the association. By default this is +id+.
0
- # * <tt>:include</tt> - Specify second-order associations that should be eager loaded when this object is loaded.
0
- # * <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
0
- # * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
+ # [:primary_key]
0
+ # Specify the method that returns the primary key used for the association. By default this is +id+.
0
+ # [:include]
0
+ # Specify second-order associations that should be eager loaded when this object is loaded.
0
+ # [:as]
0
+ # Specifies a polymorphic interface (See <tt>belongs_to</tt>).
0
+ # [:select]
0
+ # By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
       # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
0
- # * <tt>:through</tt>: Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
0
+ # [:through]
0
+ # Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
0
       # are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a
0
       # <tt>has_one</tt> or <tt>belongs_to</tt> association on the join model.
0
- # * <tt>:source</tt> - Specifies the source association name used by <tt>has_one :through</tt> queries. Only use it if the name cannot be
0
+ # [:source]
0
+ # Specifies the source association name used by <tt>has_one :through</tt> queries. Only use it if the name cannot be
0
       # inferred from the association. <tt>has_one :favorite, :through => :favorites</tt> will look for a
0
       # <tt>:favorite</tt> on Favorite, unless a <tt>:source</tt> is given.
0
- # * <tt>:source_type</tt> - Specifies type of the source association used by <tt>has_one :through</tt> queries where the source
0
+ # [:source_type]
0
+ # Specifies type of the source association used by <tt>has_one :through</tt> queries where the source
0
       # association is a polymorphic +belongs_to+.
0
- # * <tt>:readonly</tt> - If true, the associated object is readonly through the association.
0
- # * <tt>:validate</tt> - If false, don't validate the associated object when saving the parent object. +false+ by default.
0
+ # [:readonly]
0
+ # If true, the associated object is readonly through the association.
0
+ # [:validate]
0
+ # If false, don't validate the associated object when saving the parent object. +false+ by default.
0
       #
0
       # Option examples:
0
       # has_one :credit_card, :dependent => :destroy # destroys the associated credit card
0
@@ -859,18 +892,34 @@ module ActiveRecord
0
         end
0
       end
0
 
0
- # Adds the following methods for retrieval and query for a single associated object for which this object holds an id:
0
- # +association+ is replaced with the symbol passed as the first argument, so
0
- # <tt>belongs_to :author</tt> would add among others <tt>author.nil?</tt>.
0
- # * <tt>association(force_reload = false)</tt> - Returns the associated object. +nil+ is returned if none is found.
0
- # * <tt>association=(associate)</tt> - Assigns the associate object, extracts the primary key, and sets it as the foreign key.
0
- # * <tt>association.nil?</tt> - Returns +true+ if there is no associated object.
0
- # * <tt>build_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated
0
+ # Specifies a one-to-one association with another class. This method should only be used
0
+ # if this class contains the foreign key. If the other class contains the foreign key,
0
+ # then you should use +has_one+ instead. See also ActiveRecord::Associations::ClassMethods's overview
0
+ # on when to use +has_one+ and when to use +belongs_to+.
0
+ #
0
+ # Methods will be added for retrieval and query for a single associated object, for which
0
+ # this object holds an id:
0
+ #
0
+ # [association(force_reload = false)]
0
+ # Returns the associated object. +nil+ is returned if none is found.
0
+ # [association=(associate)]
0
+ # Assigns the associate object, extracts the primary key, and sets it as the foreign key.
0
+ # [association.nil?]
0
+ # Returns +true+ if there is no associated object.
0
+ # [build_association(attributes = {})]
0
+ # Returns a new object of the associated type that has been instantiated
0
       # with +attributes+ and linked to this object through a foreign key, but has not yet been saved.
0
- # * <tt>create_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated
0
- # with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
0
+ # [create_association(attributes = {})]
0
+ # Returns a new object of the associated type that has been instantiated
0
+ # with +attributes+, linked to this object through a foreign key, and that
0
+ # has already been saved (if it passed the validation).
0
       #
0
- # Example: A Post class declares <tt>belongs_to :author</tt>, which will add:
0
+ # (+association+ is replaced with the symbol passed as the first argument, so
0
+ # <tt>belongs_to :author</tt> would add among others <tt>author.nil?</tt>.)
0
+ #
0
+ # === Example
0
+ #
0
+ # A Post class declares <tt>belongs_to :author</tt>, which will add:
0
       # * <tt>Post#author</tt> (similar to <tt>Author.find(author_id)</tt>)
0
       # * <tt>Post#author=(author)</tt> (similar to <tt>post.author_id = author.id</tt>)
0
       # * <tt>Post#author?</tt> (similar to <tt>post.author == some_author</tt>)
0
@@ -879,23 +928,30 @@ module ActiveRecord
0
       # * <tt>Post#create_author</tt> (similar to <tt>post.author = Author.new; post.author.save; post.author</tt>)
0
       # The declaration can also include an options hash to specialize the behavior of the association.
0
       #
0
- # Options are:
0
- # * <tt>:class_name</tt> - Specify the class name of the association. Use it only if that name can't be inferred
0
+ # === Options
0
+ #
0
+ # [:class_name]
0
+ # Specify the class name of the association. Use it only if that name can't be inferred
0
       # from the association name. So <tt>has_one :author</tt> will by default be linked to the Author class, but
0
       # if the real class name is Person, you'll have to specify it with this option.
0
- # * <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
+ # [:conditions]
0
+ # Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
       # SQL fragment, such as <tt>authorized = 1</tt>.
0
- # * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
+ # [:select]
0
+ # By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
       # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
0
- # * <tt>:foreign_key</tt> - Specify the foreign key used for the association. By default this is guessed to be the name
0
+ # [:foreign_key]
0
+ # Specify the foreign key used for the association. By default this is guessed to be the name
0
       # of the association with an "_id" suffix. So a class that defines a <tt>belongs_to :person</tt> association will use
0
       # "person_id" as the default <tt>:foreign_key</tt>. Similarly, <tt>belongs_to :favorite_person, :class_name => "Person"</tt>
0
       # will use a foreign key of "favorite_person_id".
0
- # * <tt>:dependent</tt> - If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
0
+ # [:dependent]
0
+ # If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
0
       # <tt>:delete</tt>, the associated object is deleted *without* calling its destroy method. This option should not be specified when
0
       # <tt>belongs_to</tt> is used in conjunction with a <tt>has_many</tt> relationship on another class because of the potential to leave
0
       # orphaned records behind.
0
- # * <tt>:counter_cache</tt> - Caches the number of belonging objects on the associate class through the use of +increment_counter+
0
+ # [:counter_cache]
0
+ # Caches the number of belonging objects on the associate class through the use of +increment_counter+
0
       # and +decrement_counter+. The counter cache is incremented when an object of this class is created and decremented when it's
0
       # destroyed. This requires that a column named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging Comment class)
0
       # is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing
0
@@ -903,12 +959,16 @@ module ActiveRecord
0
       # When creating a counter cache column, the database statement or migration must specify a default value of <tt>0</tt>, failing to do
0
       # this results in a counter with +NULL+ value, which will never increment.
0
       # Note: Specifying a counter cache will add it to that model's list of readonly attributes using +attr_readonly+.
0
- # * <tt>:include</tt> - Specify second-order associations that should be eager loaded when this object is loaded.
0
- # * <tt>:polymorphic</tt> - Specify this association is a polymorphic association by passing +true+.
0
+ # [:include]
0
+ # Specify second-order associations that should be eager loaded when this object is loaded.
0
+ # [:polymorphic]
0
+ # Specify this association is a polymorphic association by passing +true+.
0
       # Note: If you've enabled the counter cache, then you may want to add the counter cache attribute
0
       # to the +attr_readonly+ list in the associated classes (e.g. <tt>class Post; attr_readonly :comments_count; end</tt>).
0
- # * <tt>:readonly</tt> - If true, the associated object is readonly through the association.
0
- # * <tt>:validate</tt> - If false, don't validate the associated objects when saving the parent object. +false+ by default.
0
+ # [:readonly]
0
+ # If true, the associated object is readonly through the association.
0
+ # [:validate]
0
+ # If false, don't validate the associated objects when saving the parent object. +false+ by default.
0
       #
0
       # Option examples:
0
       # belongs_to :firm, :foreign_key => "client_of"
0
@@ -994,8 +1054,9 @@ module ActiveRecord
0
         configure_dependency_for_belongs_to(reflection)
0
       end
0
 
0
- # Associates two classes via an intermediate join table. Unless the join table is explicitly specified as
0
- # an option, it is guessed using the lexical order of the class names. So a join between Developer and Project
0
+ # Specifies a many-to-many relationship with another class. This associates two classes via an
0
+ # intermediate join table. Unless the join table is explicitly specified as an option, it is
0
+ # guessed using the lexical order of the class names. So a join between Developer and Project
0
       # will give the default join table name of "developers_projects" because "D" outranks "P". Note that this precedence
0
       # is calculated using the <tt><</tt> operator for String. This means that if the strings are of different lengths,
0
       # and the strings are equal when compared up to the shortest length, then the longer string is considered of higher
0
@@ -1010,28 +1071,48 @@ module ActiveRecord
0
       # associations with attributes to a real join model (see introduction).
0
       #
0
       # Adds the following methods for retrieval and query:
0
- # +collection+ is replaced with the symbol passed as the first argument, so
0
- # <tt>has_and_belongs_to_many :categories</tt> would add among others <tt>categories.empty?</tt>.
0
- # * <tt>collection(force_reload = false)</tt> - Returns an array of all the associated objects.
0
+ #
0
+ # [collection(force_reload = false)]
0
+ # Returns an array of all the associated objects.
0
       # An empty array is returned if none are found.
0
- # * <tt>collection<<(object, ...)</tt> - Adds one or more objects to the collection by creating associations in the join table
0
+ # [collection<<(object, ...)]
0
+ # Adds one or more objects to the collection by creating associations in the join table
0
       # (<tt>collection.push</tt> and <tt>collection.concat</tt> are aliases to this method).
0
- # * <tt>collection.delete(object, ...)</tt> - Removes one or more objects from the collection by removing their associations from the join table.
0
+ # [collection.delete(object, ...)]
0
+ # Removes one or more objects from the collection by removing their associations from the join table.
0
       # This does not destroy the objects.
0
- # * <tt>collection=objects</tt> - Replaces the collection's content by deleting and adding objects as appropriate.
0
- # * <tt>collection_singular_ids</tt> - Returns an array of the associated objects' ids.
0
- # * <tt>collection_singular_ids=ids</tt> - Replace the collection by the objects identified by the primary keys in +ids+.
0
- # * <tt>collection.clear</tt> - Removes every object from the collection. This does not destroy the objects.
0
- # * <tt>collection.empty?</tt> - Returns +true+ if there are no associated objects.
0
- # * <tt>collection.size</tt> - Returns the number of associated objects.
0
- # * <tt>collection.find(id)</tt> - Finds an associated object responding to the +id+ and that
0
+ # [collection=objects]
0
+ # Replaces the collection's content by deleting and adding objects as appropriate.
0
+ # [collection_singular_ids]
0
+ # Returns an array of the associated objects' ids.
0
+ # [collection_singular_ids=ids]
0
+ # Replace the collection by the objects identified by the primary keys in +ids+.
0
+ # [collection.clear]
0
+ # Removes every object from the collection. This does not destroy the objects.
0
+ # [collection.empty?]
0
+ # Returns +true+ if there are no associated objects.
0
+ # [collection.size]
0
+ # Returns the number of associated objects.
0
+ # [collection.find(id)]
0
+ # Finds an associated object responding to the +id+ and that
0
       # meets the condition that it has to be associated with this object.
0
- # * <tt>collection.build(attributes = {})</tt> - Returns a new object of the collection type that has been instantiated
0
+ # Uses the same rules as ActiveRecord::Base.find.
0
+ # [collection.exist?(...)]
0
+ # Checks whether an associated object with the given conditions exists.
0
+ # Uses the same rules as ActiveRecord::Base.exists?.
0
+ # [collection.build(attributes = {})]
0
+ # Returns a new object of the collection type that has been instantiated
0
       # with +attributes+ and linked to this object through the join table, but has not yet been saved.
0
- # * <tt>collection.create(attributes = {})</tt> - Returns a new object of the collection type that has been instantiated
0
+ # [collection.create(attributes = {})]
0
+ # Returns a new object of the collection type that has been instantiated
0
       # with +attributes+, linked to this object through the join table, and that has already been saved (if it passed the validation).
0
       #
0
- # Example: A Developer class declares <tt>has_and_belongs_to_many :projects</tt>, which will add:
0
+ # (+collection+ is replaced with the symbol passed as the first argument, so
0
+ # <tt>has_and_belongs_to_many :categories</tt> would add among others <tt>categories.empty?</tt>.)
0
+ #
0
+ # === Example
0
+ #
0
+ # A Developer class declares <tt>has_and_belongs_to_many :projects</tt>, which will add:
0
       # * <tt>Developer#projects</tt>
0
       # * <tt>Developer#projects<<</tt>
0
       # * <tt>Developer#projects.delete</tt>
0
@@ -1042,44 +1123,64 @@ module ActiveRecord
0
       # * <tt>Developer#projects.empty?</tt>
0
       # * <tt>Developer#projects.size</tt>
0
       # * <tt>Developer#projects.find(id)</tt>
0
+ # * <tt>Developer#clients.exist?(...)</tt>
0
       # * <tt>Developer#projects.build</tt> (similar to <tt>Project.new("project_id" => id)</tt>)
0
       # * <tt>Developer#projects.create</tt> (similar to <tt>c = Project.new("project_id" => id); c.save; c</tt>)
0
       # The declaration may include an options hash to specialize the behavior of the association.
0
       #
0
- # Options are:
0
- # * <tt>:class_name</tt> - Specify the class name of the association. Use it only if that name can't be inferred
0
+ # === Options
0
+ #
0
+ # [:class_name]
0
+ # Specify the class name of the association. Use it only if that name can't be inferred
0
       # from the association name. So <tt>has_and_belongs_to_many :projects</tt> will by default be linked to the
0
       # Project class, but if the real class name is SuperProject, you'll have to specify it with this option.
0
- # * <tt>:join_table</tt> - Specify the name of the join table if the default based on lexical order isn't what you want.
0
- # WARNING: If you're overwriting the table name of either class, the +table_name+ method MUST be declared underneath any
0
- # +has_and_belongs_to_many+ declaration in order to work.
0
- # * <tt>:foreign_key</tt> - Specify the foreign key used for the association. By default this is guessed to be the name
0
+ # [:join_table]
0
+ # Specify the name of the join table if the default based on lexical order isn't what you want.
0
+ # <b>WARNING:</b> If you're overwriting the table name of either class, the +table_name+ method
0
+ # MUST be declared underneath any +has_and_belongs_to_many+ declaration in order to work.
0
+ # [:foreign_key]
0
+ # Specify the foreign key used for the association. By default this is guessed to be the name
0
       # of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_and_belongs_to_many+ association
0
       # will use "person_id" as the default <tt>:foreign_key</tt>.
0
- # * <tt>:association_foreign_key</tt> - Specify the association foreign key used for the association. By default this is
0
+ # [:association_foreign_key]
0
+ # Specify the association foreign key used for the association. By default this is
0
       # guessed to be the name of the associated class in lower-case and "_id" suffixed. So if the associated class is Project,
0
       # the +has_and_belongs_to_many+ association will use "project_id" as the default <tt>:association_foreign_key</tt>.
0
- # * <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
+ # [:conditions]
0
+ # Specify the conditions that the associated object must meet in order to be included as a +WHERE+
0
       # SQL fragment, such as <tt>authorized = 1</tt>. Record creations from the association are scoped if a hash is used.
0
       # <tt>has_many :posts, :conditions => {:published => true}</tt> will create published posts with <tt>@blog.posts.create</tt>
0
       # or <tt>@blog.posts.build</tt>.
0
- # * <tt>:order</tt> - Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
0
+ # [:order]
0
+ # Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
0
       # such as <tt>last_name, first_name DESC</tt>
0
- # * <tt>:uniq</tt> - If true, duplicate associated objects will be ignored by accessors and query methods.
0
- # * <tt>:finder_sql</tt> - Overwrite the default generated SQL statement used to fetch the association with a manual statement
0
- # * <tt>:delete_sql</tt> - Overwrite the default generated SQL statement used to remove links between the associated
0
+ # [:uniq]
0
+ # If true, duplicate associated objects will be ignored by accessors and query methods.
0
+ # [:finder_sql]
0
+ # Overwrite the default generated SQL statement used to fetch the association with a manual statement
0
+ # [:delete_sql]
0
+ # Overwrite the default generated SQL statement used to remove links between the associated
0
       # classes with a manual statement.
0
- # * <tt>:insert_sql</tt> - Overwrite the default generated SQL statement used to add links between the associated classes
0
+ # [:insert_sql]
0
+ # Overwrite the default generated SQL statement used to add links between the associated classes
0
       # with a manual statement.
0
- # * <tt>:extend</tt> - Anonymous module for extending the proxy, see "Association extensions".
0
- # * <tt>:include</tt> - Specify second-order associations that should be eager loaded when the collection is loaded.
0
- # * <tt>:group</tt> - An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause.
0
- # * <tt>:limit</tt> - An integer determining the limit on the number of rows that should be returned.
0
- # * <tt>:offset</tt> - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
0
- # * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
+ # [:extend]
0
+ # Anonymous module for extending the proxy, see "Association extensions".
0
+ # [:include]
0
+ # Specify second-order associations that should be eager loaded when the collection is loaded.
0
+ # [:group]
0
+ # An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause.
0
+ # [:limit]
0
+ # An integer determining the limit on the number of rows that should be returned.
0
+ # [:offset]
0
+ # An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
0
+ # [:select]
0
+ # By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
0
       # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
0
- # * <tt>:readonly</tt> - If true, all the associated objects are readonly through the association.
0
- # * <tt>:validate</tt> - If false, don't validate the associated objects when saving the parent object. +true+ by default.
0
+ # [:readonly]
0
+ # If true, all the associated objects are readonly through the association.
0
+ # [:validate]
0
+ # If false, don't validate the associated objects when saving the parent object. +true+ by default.
0
       #
0
       # Option examples:
0
       # has_and_belongs_to_many :projects

Comments

    No one has commented yet.