Ticket #8899: doc_grammar_fixes_for_associations.diff
| File doc_grammar_fixes_for_associations.diff, 24.3 kB (added by seanhussey, 2 years ago) |
|---|
-
activerecord/lib/active_record/associations/association_proxy.rb
old new 143 143 end 144 144 145 145 # Can be overwritten by associations that might have the foreign key available for an association without 146 # having the object itself (and still being a new record). Currently, only belongs_to present this scenario.146 # having the object itself (and still being a new record). Currently, only belongs_to presents this scenario. 147 147 def foreign_key_present 148 148 false 149 149 end -
activerecord/lib/active_record/associations/association_collection.rb
old new 65 65 66 66 # Removes all records from this association. Returns +self+ so method calls may be chained. 67 67 def clear 68 return self if length.zero? # forces load_target if hasn't happened already68 return self if length.zero? # forces load_target if it hasn't happened already 69 69 70 70 if @reflection.options[:dependent] && @reflection.options[:dependent] == :delete_all 71 71 destroy_all -
activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
old new 14 14 end 15 15 16 16 def create(attributes = {}) 17 # Can't use Base.create since the foreign key may be a protected attribute.17 # Can't use Base.create because the foreign key may be a protected attribute. 18 18 if attributes.is_a?(Array) 19 19 attributes.collect { |attr| create(attr) } 20 20 else … … 136 136 end 137 137 138 138 # Join tables with additional columns on top of the two foreign keys must be considered ambigious unless a select 139 # clause has been explicitly defined. Otherwise you can get broken records back, if, say, the join column also has140 # an d id column, whichwill then overwrite the id column of the records coming back.139 # clause has been explicitly defined. Otherwise you can get broken records back, if, for example, the join column also has 140 # an id column. This will then overwrite the id column of the records coming back. 141 141 def finding_with_ambigious_select?(select_clause) 142 142 !select_clause && @owner.connection.columns(@reflection.options[:join_table], "Join Table Columns").size != 2 143 143 end -
activerecord/lib/active_record/associations/has_one_association.rb
old new 76 76 end 77 77 78 78 def new_record(replace_existing) 79 # make sure we load the target first, if we plan on replacing the existing79 # Make sure we load the target first, if we plan on replacing the existing 80 80 # instance. Otherwise, if the target has not previously been loaded 81 81 # elsewhere, the instance we create will get orphaned. 82 82 load_target if replace_existing -
activerecord/lib/active_record/associations/has_many_through_association.rb
old new 67 67 68 68 [:push, :concat].each { |method| alias_method method, :<< } 69 69 70 # Remove +records+ from this association. Does not destroy +records+.70 # Removes +records+ from this association. Does not destroy +records+. 71 71 def delete(*records) 72 72 records = flatten_deeper(records) 73 73 records.each { |associate| raise_on_type_mismatch(associate) } -
activerecord/lib/active_record/associations.rb
old new 208 208 # 209 209 # == Is it a belongs_to or has_one association? 210 210 # 211 # Both express a 1-1 relationship , the difference is mostly where to place the foreign key, which goes on the table for the class212 # saying belongs_to. Example:211 # Both express a 1-1 relationship. The difference is mostly where to place the foreign key, which goes on the table for the class 212 # declaring the belongs_to relationship. Example: 213 213 # 214 214 # class User < ActiveRecord::Base 215 215 # # I reference an account. … … 262 262 # === Association callbacks 263 263 # 264 264 # Similiar to the normal callbacks that hook into the lifecycle of an Active Record object, you can also define callbacks that get 265 # trigged when you add an object to or remov ing an object from aassociation collection. Example:265 # trigged when you add an object to or remove an object from an association collection. Example: 266 266 # 267 267 # class Project 268 268 # has_and_belongs_to_many :developers, :after_add => :evaluate_velocity … … 281 281 # Possible callbacks are: before_add, after_add, before_remove and after_remove. 282 282 # 283 283 # Should any of the before_add callbacks throw an exception, the object does not get added to the collection. Same with 284 # the before_remove callbacks ,if an exception is thrown the object doesn't get removed.284 # the before_remove callbacks; if an exception is thrown the object doesn't get removed. 285 285 # 286 286 # === Association extensions 287 287 # 288 # The proxy objects that control sthe access to associations can be extended through anonymous modules. This is especially288 # The proxy objects that control the access to associations can be extended through anonymous modules. This is especially 289 289 # beneficial for adding new finders, creators, and other factory-type methods that are only used as part of this association. 290 290 # Example: 291 291 # … … 566 566 # 567 567 # == Options 568 568 # 569 # All of the association macros can be specialized through options which makes more complex casesthan the simple and guessable ones569 # All of the association macros can be specialized through options. This makes cases more complex than the simple and guessable ones 570 570 # possible. 571 571 module ClassMethods 572 # Adds the following methods for retrieval and query of collections of associated objects .572 # Adds the following methods for retrieval and query of collections of associated objects: 573 573 # +collection+ is replaced with the symbol passed as the first argument, so 574 574 # <tt>has_many :clients</tt> would add among others <tt>clients.empty?</tt>. 575 575 # * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects. … … 578 578 # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by setting their foreign keys to NULL. 579 579 # This will also destroy the objects if they're declared as belongs_to and dependent on this model. 580 580 # * <tt>collection=objects</tt> - replaces the collections content by deleting and adding objects as appropriate. 581 # * <tt>collection_singular_ids</tt> - returns an array of the associated objects ids581 # * <tt>collection_singular_ids</tt> - returns an array of the associated objects' ids 582 582 # * <tt>collection_singular_ids=ids</tt> - replace the collection by the objects identified by the primary keys in +ids+ 583 583 # * <tt>collection.clear</tt> - removes every object from the collection. This destroys the associated objects if they 584 584 # are associated with <tt>:dependent => :destroy</tt>, deletes them directly from the database if <tt>:dependent => :delete_all</tt>, 585 # and sets their foreign keys to NULL otherwise.585 # or otherwise sets their foreign keys to NULL. 586 586 # * <tt>collection.empty?</tt> - returns true if there are no associated objects. 587 587 # * <tt>collection.size</tt> - returns the number of associated objects. 588 588 # * <tt>collection.find</tt> - finds an associated object according to the same rules as Base.find. 589 589 # * <tt>collection.build(attributes = {})</tt> - returns a new object of the collection type that has been instantiated 590 # with +attributes+ and linked to this object through a foreign key but has not yet been saved. *Note:* This only works if an590 # with +attributes+ and linked to this object through a foreign key, but has not yet been saved. *Note:* This only works if an 591 591 # associated object already exists, not if it's nil! 592 592 # * <tt>collection.create(attributes = {})</tt> - returns a new object of the collection type that has been instantiated 593 # with +attributes+ and linked to this object through a foreign keyand that has already been saved (if it passed the validation).593 # with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation). 594 594 # *Note:* This only works if an associated object already exists, not if it's nil! 595 595 # 596 596 # Example: A Firm class declares <tt>has_many :clients</tt>, which will add: … … 613 613 # from the association name. So <tt>has_many :products</tt> will by default be linked to the +Product+ class, but 614 614 # if the real class name is +SpecialProduct+, you'll have to specify it with this option. 615 615 # * <tt>:conditions</tt> - specify the conditions that the associated objects must meet in order to be included as a "WHERE" 616 # sqlfragment, such as "price > 5 AND name LIKE 'B%'".617 # * <tt>:order</tt> - specify the order in which the associated objects are returned as a "ORDER BY" sqlfragment,616 # SQL fragment, such as "price > 5 AND name LIKE 'B%'". 617 # * <tt>:order</tt> - specify the order in which the associated objects are returned as a "ORDER BY" SQL fragment, 618 618 # such as "last_name, first_name DESC" 619 # * <tt>:group</tt> - specify the attribute by which the associated objects are returned as a "GROUP BY" sqlfragment,619 # * <tt>:group</tt> - specify the attribute by which the associated objects are returned as a "GROUP BY" SQL fragment, 620 620 # such as "category" 621 621 # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 622 622 # of this class in lower-case and "_id" suffixed. So a +Person+ class that makes a has_many association will use "person_id" … … 636 636 # associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. 637 637 # * <tt>:counter_sql</tt> - specify a complete SQL statement to fetch the size of the association. If +:finder_sql+ is 638 638 # specified but +:counter_sql+, +:counter_sql+ will be generated by replacing SELECT ... FROM with SELECT COUNT(*) FROM. 639 # * <tt>:extend</tt> - specify a named module for extending the proxy , see "Association extensions".639 # * <tt>:extend</tt> - specify a named module for extending the proxy. See "Association extensions". 640 640 # * <tt>:include</tt> - specify second-order associations that should be eager loaded when the collection is loaded. 641 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BYSQL-clause.641 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the "GROUP BY" SQL-clause. 642 642 # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned. 643 643 # * <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. 644 644 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not … … 684 684 add_deprecated_api_for_has_many(reflection.name) 685 685 end 686 686 687 # Adds the following methods for retrieval and query of a single associated object .687 # Adds the following methods for retrieval and query of a single associated object: 688 688 # +association+ is replaced with the symbol passed as the first argument, so 689 689 # <tt>has_one :manager</tt> would add among others <tt>manager.nil?</tt>. 690 690 # * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found. … … 692 692 # and saves the associate object. 693 693 # * <tt>association.nil?</tt> - returns true if there is no associated object. 694 694 # * <tt>build_association(attributes = {})</tt> - returns a new object of the associated type that has been instantiated 695 # with +attributes+ and linked to this object through a foreign key but has not yet been saved. Note: This ONLY works if695 # with +attributes+ and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if 696 696 # an association already exists. It will NOT work if the association is nil. 697 697 # * <tt>create_association(attributes = {})</tt> - returns a new object of the associated type that has been instantiated 698 # with +attributes+ and linked to this object through a foreign keyand that has already been saved (if it passed the validation).698 # with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation). 699 699 # 700 700 # Example: An Account class declares <tt>has_one :beneficiary</tt>, which will add: 701 701 # * <tt>Account#beneficiary</tt> (similar to <tt>Beneficiary.find(:first, :conditions => "account_id = #{id}")</tt>) … … 711 711 # from the association name. So <tt>has_one :manager</tt> will by default be linked to the +Manager+ class, but 712 712 # if the real class name is +Person+, you'll have to specify it with this option. 713 713 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a "WHERE" 714 # sqlfragment, such as "rank = 5".714 # SQL fragment, such as "rank = 5". 715 715 # * <tt>:order</tt> - specify the order from which the associated object will be picked at the top. Specified as 716 # an "ORDER BY" sqlfragment, such as "last_name, first_name DESC"716 # an "ORDER BY" SQL fragment, such as "last_name, first_name DESC" 717 717 # * <tt>:dependent</tt> - if set to :destroy (or true) the associated object is destroyed when this object is. If set to 718 718 # :delete the associated object is deleted *without* calling its destroy method. If set to :nullify the associated 719 719 # object's foreign key is set to NULL. Also, association is assigned. … … 753 753 deprecated_association_comparison_method(reflection.name, reflection.class_name) 754 754 end 755 755 756 # Adds the following methods for retrieval and query for a single associated object that this object holds an id to.756 # Adds the following methods for retrieval and query for a single associated object for which this object holds an id: 757 757 # +association+ is replaced with the symbol passed as the first argument, so 758 758 # <tt>belongs_to :author</tt> would add among others <tt>author.nil?</tt>. 759 759 # * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found. 760 760 # * <tt>association=(associate)</tt> - assigns the associate object, extracts the primary key, and sets it as the foreign key. 761 761 # * <tt>association.nil?</tt> - returns true if there is no associated object. 762 762 # * <tt>build_association(attributes = {})</tt> - returns a new object of the associated type that has been instantiated 763 # with +attributes+ and linked to this object through a foreign key but has not yet been saved.763 # with +attributes+ and linked to this object through a foreign key, but has not yet been saved. 764 764 # * <tt>create_association(attributes = {})</tt> - returns a new object of the associated type that has been instantiated 765 # with +attributes+ and linked to this object through a foreign keyand that has already been saved (if it passed the validation).765 # with +attributes+, linked to this object through a foreign key, and that has already been saved (if it passed the validation). 766 766 # 767 767 # Example: A Post class declares <tt>belongs_to :author</tt>, which will add: 768 768 # * <tt>Post#author</tt> (similar to <tt>Author.find(author_id)</tt>) … … 778 778 # from the association name. So <tt>has_one :author</tt> will by default be linked to the +Author+ class, but 779 779 # if the real class name is +Person+, you'll have to specify it with this option. 780 780 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a "WHERE" 781 # sqlfragment, such as "authorized = 1".781 # SQL fragment, such as "authorized = 1". 782 782 # * <tt>:order</tt> - specify the order from which the associated object will be picked at the top. Specified as 783 # an "ORDER BY" sqlfragment, such as "last_name, first_name DESC"783 # an "ORDER BY" SQL fragment, such as "last_name, first_name DESC" 784 784 # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 785 785 # of the associated class in lower-case and "_id" suffixed. So a +Person+ class that makes a belongs_to association to a 786 786 # +Boss+ class will use "boss_id" as the default foreign_key. 787 787 # * <tt>:counter_cache</tt> - caches the number of belonging objects on the associate class through use of increment_counter 788 788 # and decrement_counter. The counter cache is incremented when an object of this class is created and decremented when it's 789 789 # destroyed. This requires that a column named "#{table_name}_count" (such as comments_count for a belonging Comment class) 790 # is used on the associate class (such as a Post class). You can also specify a custom counter cache column by given that791 # name instead of a true/false value to this option (e.g., <tt>:counter_cache => :my_custom_counter</tt>.)790 # is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing 791 # a column name instead of a true/false value to this option (e.g., <tt>:counter_cache => :my_custom_counter</tt>.) 792 792 # * <tt>:include</tt> - specify second-order associations that should be eager loaded when this object is loaded. 793 793 # * <tt>:polymorphic</tt> - specify this association is a polymorphic association by passing true. 794 794 # … … 883 883 # ReadOnly (because we can't save changes to the additional attrbutes). It's strongly recommended that you upgrade any 884 884 # associations with attributes to a real join model (see introduction). 885 885 # 886 # Adds the following methods for retrieval and query .886 # Adds the following methods for retrieval and query: 887 887 # +collection+ is replaced with the symbol passed as the first argument, so 888 888 # <tt>has_and_belongs_to_many :categories</tt> would add among others <tt>categories.empty?</tt>. 889 889 # * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects. … … 897 897 # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by removing their associations from the join table. 898 898 # This does not destroy the objects. 899 899 # * <tt>collection=objects</tt> - replaces the collections content by deleting and adding objects as appropriate. 900 # * <tt>collection_singular_ids</tt> - returns an array of the associated objects ids900 # * <tt>collection_singular_ids</tt> - returns an array of the associated objects' ids 901 901 # * <tt>collection_singular_ids=ids</tt> - replace the collection by the objects identified by the primary keys in +ids+ 902 902 # * <tt>collection.clear</tt> - removes every object from the collection. This does not destroy the objects. 903 903 # * <tt>collection.empty?</tt> - returns true if there are no associated objects. … … 905 905 # * <tt>collection.find(id)</tt> - finds an associated object responding to the +id+ and that 906 906 # meets the condition that it has to be associated with this object. 907 907 # * <tt>collection.build(attributes = {})</tt> - returns a new object of the collection type that has been instantiated 908 # with +attributes+ and linked to this object through the join table but has not yet been saved.908 # with +attributes+ and linked to this object through the join table, but has not yet been saved. 909 909 # * <tt>collection.create(attributes = {})</tt> - returns a new object of the collection type that has been instantiated 910 # with +attributes+ and linked to this object through the join tableand that has already been saved (if it passed the validation).910 # with +attributes+, linked to this object through the join table, and that has already been saved (if it passed the validation). 911 911 # 912 912 # Example: An Developer class declares <tt>has_and_belongs_to_many :projects</tt>, which will add: 913 913 # * <tt>Developer#projects</tt> … … 938 938 # guessed to be the name of the associated class in lower-case and "_id" suffixed. So if the associated class is +Project+, 939 939 # the has_and_belongs_to_many association will use "project_id" as the default association foreign_key. 940 940 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a "WHERE" 941 # sqlfragment, such as "authorized = 1".942 # * <tt>:order</tt> - specify the order in which the associated objects are returned as a "ORDER BY" sqlfragment, such as "last_name, first_name DESC"941 # SQL fragment, such as "authorized = 1". 942 # * <tt>:order</tt> - specify the order in which the associated objects are returned as a "ORDER BY" SQL fragment, such as "last_name, first_name DESC" 943 943 # * <tt>:uniq</tt> - if set to true, duplicate associated objects will be ignored by accessors and query methods 944 # * <tt>:finder_sql</tt> - overwrite the default generated SQL used to fetch the association with a manual one945 # * <tt>:delete_sql</tt> - overwrite the default generated SQL used to remove links between the associated946 # classes with a manual one947 # * <tt>:insert_sql</tt> - overwrite the default generated SQL used to add links between the associated classes948 # with a manual one944 # * <tt>:finder_sql</tt> - overwrite the default generated SQL statement used to fetch the association with a manual statement 945 # * <tt>:delete_sql</tt> - overwrite the default generated SQL statement used to remove links between the associated 946 # classes with a manual statement 947 # * <tt>:insert_sql</tt> - overwrite the default generated SQL statement used to add links between the associated classes 948 # with a manual statement 949 949 # * <tt>:extend</tt> - anonymous module for extending the proxy, see "Association extensions". 950 950 # * <tt>:include</tt> - specify second-order associations that should be eager loaded when the collection is loaded. 951 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BYSQL-clause.951 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the "GROUP BY" SQL-clause. 952 952 # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned. 953 953 # * <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. 954 954 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not