Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    143143        end 
    144144 
    145145        # 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. 
    147147        def foreign_key_present 
    148148          false 
    149149        end 
  • activerecord/lib/active_record/associations/association_collection.rb

    old new  
    6565 
    6666      # Removes all records from this association.  Returns +self+ so method calls may be chained. 
    6767      def clear 
    68         return self if length.zero? # forces load_target if hasn't happened already 
     68        return self if length.zero? # forces load_target if it hasn't happened already 
    6969 
    7070        if @reflection.options[:dependent] && @reflection.options[:dependent] == :delete_all 
    7171          destroy_all 
  • activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb

    old new  
    1414      end 
    1515 
    1616      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. 
    1818        if attributes.is_a?(Array) 
    1919          attributes.collect { |attr| create(attr) } 
    2020        else 
     
    136136        end 
    137137 
    138138        # 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 has 
    140         # and id column, which will 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. 
    141141        def finding_with_ambigious_select?(select_clause) 
    142142          !select_clause && @owner.connection.columns(@reflection.options[:join_table], "Join Table Columns").size != 2 
    143143        end 
  • activerecord/lib/active_record/associations/has_one_association.rb

    old new  
    7676        end 
    7777 
    7878        def new_record(replace_existing) 
    79           # make sure we load the target first, if we plan on replacing the existing 
     79          # Make sure we load the target first, if we plan on replacing the existing 
    8080          # instance. Otherwise, if the target has not previously been loaded 
    8181          # elsewhere, the instance we create will get orphaned. 
    8282          load_target if replace_existing 
  • activerecord/lib/active_record/associations/has_many_through_association.rb

    old new  
    6767 
    6868      [:push, :concat].each { |method| alias_method method, :<< } 
    6969 
    70       # Remove +records+ from this association.  Does not destroy +records+. 
     70      # Removes +records+ from this association.  Does not destroy +records+. 
    7171      def delete(*records) 
    7272        records = flatten_deeper(records) 
    7373        records.each { |associate| raise_on_type_mismatch(associate) } 
  • activerecord/lib/active_record/associations.rb

    old new  
    208208    # 
    209209    # == Is it a belongs_to or has_one association? 
    210210    # 
    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     # 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: 
    213213    # 
    214214    #   class User < ActiveRecord::Base 
    215215    #     # I reference an account. 
     
    262262    # === Association callbacks 
    263263    # 
    264264    # 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 removing an object from a association collection. Example: 
     265    # trigged when you add an object to or remove an object from an association collection. Example: 
    266266    # 
    267267    #   class Project 
    268268    #     has_and_belongs_to_many :developers, :after_add => :evaluate_velocity 
     
    281281    # Possible callbacks are: before_add, after_add, before_remove and after_remove. 
    282282    # 
    283283    # 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. 
    285285    # 
    286286    # === Association extensions 
    287287    # 
    288     # The proxy objects that controls the access to associations can be extended through anonymous modules. This is especially 
     288    # The proxy objects that control the access to associations can be extended through anonymous modules. This is especially 
    289289    # beneficial for adding new finders, creators, and other factory-type methods that are only used as part of this association. 
    290290    # Example: 
    291291    # 
     
    566566    # 
    567567    # == Options 
    568568    # 
    569     # All of the association macros can be specialized through options which makes more complex cases than the simple and guessable ones 
     569    # All of the association macros can be specialized through options. This makes cases more complex than the simple and guessable ones 
    570570    # possible. 
    571571    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: 
    573573      # +collection+ is replaced with the symbol passed as the first argument, so  
    574574      # <tt>has_many :clients</tt> would add among others <tt>clients.empty?</tt>. 
    575575      # * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects. 
     
    578578      # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by setting their foreign keys to NULL.   
    579579      #   This will also destroy the objects if they're declared as belongs_to and dependent on this model. 
    580580      # * <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 ids 
     581      # * <tt>collection_singular_ids</tt> - returns an array of the associated objects' ids 
    582582      # * <tt>collection_singular_ids=ids</tt> - replace the collection by the objects identified by the primary keys in +ids+ 
    583583      # * <tt>collection.clear</tt> - removes every object from the collection. This destroys the associated objects if they 
    584584      #   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
    586586      # * <tt>collection.empty?</tt> - returns true if there are no associated objects. 
    587587      # * <tt>collection.size</tt> - returns the number of associated objects. 
    588588      # * <tt>collection.find</tt> - finds an associated object according to the same rules as Base.find. 
    589589      # * <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 an  
     590      #   with +attributes+ and linked to this object through a foreign key, but has not yet been saved. *Note:* This only works if an  
    591591      #   associated object already exists, not if it's nil! 
    592592      # * <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 key and 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). 
    594594      #   *Note:* This only works if an associated object already exists, not if it's nil! 
    595595      # 
    596596      # Example: A Firm class declares <tt>has_many :clients</tt>, which will add: 
     
    613613      #   from the association name. So <tt>has_many :products</tt> will by default be linked to the +Product+ class, but 
    614614      #   if the real class name is +SpecialProduct+, you'll have to specify it with this option. 
    615615      # * <tt>:conditions</tt>  - specify the conditions that the associated objects must meet in order to be included as a "WHERE" 
    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, 
     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, 
    618618      #   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" sql fragment, 
     619      # * <tt>:group</tt>       - specify the attribute by which the associated objects are returned as a "GROUP BY" SQL fragment, 
    620620      #   such as "category"       
    621621      # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 
    622622      #   of this class in lower-case and "_id" suffixed. So a +Person+ class that makes a has_many association will use "person_id" 
     
    636636      #   associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. 
    637637      # * <tt>:counter_sql</tt>  - specify a complete SQL statement to fetch the size of the association. If +:finder_sql+ is 
    638638      #   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". 
    640640      # * <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 BY SQL-clause. 
     641      # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the "GROUP BY" SQL-clause. 
    642642      # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned. 
    643643      # * <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. 
    644644      # * <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 
     
    684684        add_deprecated_api_for_has_many(reflection.name) 
    685685      end 
    686686 
    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: 
    688688      # +association+ is replaced with the symbol passed as the first argument, so  
    689689      # <tt>has_one :manager</tt> would add among others <tt>manager.nil?</tt>. 
    690690      # * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found. 
     
    692692      #   and saves the associate object. 
    693693      # * <tt>association.nil?</tt> - returns true if there is no associated object. 
    694694      # * <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 if 
     695      #   with +attributes+ and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if 
    696696      #   an association already exists. It will NOT work if the association is nil. 
    697697      # * <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 key and 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). 
    699699      # 
    700700      # Example: An Account class declares <tt>has_one :beneficiary</tt>, which will add: 
    701701      # * <tt>Account#beneficiary</tt> (similar to <tt>Beneficiary.find(:first, :conditions => "account_id = #{id}")</tt>) 
     
    711711      #   from the association name. So <tt>has_one :manager</tt> will by default be linked to the +Manager+ class, but 
    712712      #   if the real class name is +Person+, you'll have to specify it with this option. 
    713713      # * <tt>:conditions</tt>  - specify the conditions that the associated object must meet in order to be included as a "WHERE" 
    714       #   sql fragment, such as "rank = 5". 
     714      #   SQL fragment, such as "rank = 5". 
    715715      # * <tt>:order</tt>       - specify the order from which the associated object will be picked at the top. Specified as 
    716       #    an "ORDER BY" sql fragment, such as "last_name, first_name DESC" 
     716      #    an "ORDER BY" SQL fragment, such as "last_name, first_name DESC" 
    717717      # * <tt>:dependent</tt>   - if set to :destroy (or true) the associated object is destroyed when this object is. If set to 
    718718      #   :delete the associated object is deleted *without* calling its destroy method. If set to :nullify the associated 
    719719      #   object's foreign key is set to NULL. Also, association is assigned. 
     
    753753        deprecated_association_comparison_method(reflection.name, reflection.class_name) 
    754754      end 
    755755 
    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: 
    757757      # +association+ is replaced with the symbol passed as the first argument, so  
    758758      # <tt>belongs_to :author</tt> would add among others <tt>author.nil?</tt>. 
    759759      # * <tt>association(force_reload = false)</tt> - returns the associated object. Nil is returned if none is found. 
    760760      # * <tt>association=(associate)</tt> - assigns the associate object, extracts the primary key, and sets it as the foreign key. 
    761761      # * <tt>association.nil?</tt> - returns true if there is no associated object. 
    762762      # * <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. 
    764764      # * <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 key and 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). 
    766766      # 
    767767      # Example: A Post class declares <tt>belongs_to :author</tt>, which will add: 
    768768      # * <tt>Post#author</tt> (similar to <tt>Author.find(author_id)</tt>) 
     
    778778      #   from the association name. So <tt>has_one :author</tt> will by default be linked to the +Author+ class, but 
    779779      #   if the real class name is +Person+, you'll have to specify it with this option. 
    780780      # * <tt>:conditions</tt>  - specify the conditions that the associated object must meet in order to be included as a "WHERE" 
    781       #   sql fragment, such as "authorized = 1". 
     781      #   SQL fragment, such as "authorized = 1". 
    782782      # * <tt>:order</tt>       - specify the order from which the associated object will be picked at the top. Specified as 
    783       #   an "ORDER BY" sql fragment, such as "last_name, first_name DESC" 
     783      #   an "ORDER BY" SQL fragment, such as "last_name, first_name DESC" 
    784784      # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 
    785785      #   of the associated class in lower-case and "_id" suffixed. So a +Person+ class that makes a belongs_to association to a 
    786786      #   +Boss+ class will use "boss_id" as the default foreign_key. 
    787787      # * <tt>:counter_cache</tt> - caches the number of belonging objects on the associate class through use of increment_counter  
    788788      #   and decrement_counter. The counter cache is incremented when an object of this class is created and decremented when it's 
    789789      #   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 that 
    791       #   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>.) 
    792792      # * <tt>:include</tt>  - specify second-order associations that should be eager loaded when this object is loaded. 
    793793      # * <tt>:polymorphic</tt> - specify this association is a polymorphic association by passing true. 
    794794      # 
     
    883883      # ReadOnly (because we can't save changes to the additional attrbutes). It's strongly recommended that you upgrade any 
    884884      # associations with attributes to a real join model (see introduction). 
    885885      # 
    886       # Adds the following methods for retrieval and query. 
     886      # Adds the following methods for retrieval and query: 
    887887      # +collection+ is replaced with the symbol passed as the first argument, so  
    888888      # <tt>has_and_belongs_to_many :categories</tt> would add among others <tt>categories.empty?</tt>. 
    889889      # * <tt>collection(force_reload = false)</tt> - returns an array of all the associated objects. 
     
    897897      # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by removing their associations from the join table.   
    898898      #   This does not destroy the objects. 
    899899      # * <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 ids 
     900      # * <tt>collection_singular_ids</tt> - returns an array of the associated objects' ids 
    901901      # * <tt>collection_singular_ids=ids</tt> - replace the collection by the objects identified by the primary keys in +ids+ 
    902902      # * <tt>collection.clear</tt> - removes every object from the collection. This does not destroy the objects. 
    903903      # * <tt>collection.empty?</tt> - returns true if there are no associated objects. 
     
    905905      # * <tt>collection.find(id)</tt> - finds an associated object responding to the +id+ and that 
    906906      #   meets the condition that it has to be associated with this object. 
    907907      # * <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. 
    909909      # * <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 table and 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). 
    911911      # 
    912912      # Example: An Developer class declares <tt>has_and_belongs_to_many :projects</tt>, which will add: 
    913913      # * <tt>Developer#projects</tt> 
     
    938938      #   guessed to be the name of the associated class in lower-case and "_id" suffixed. So if the associated class is +Project+, 
    939939      #   the has_and_belongs_to_many association will use "project_id" as the default association foreign_key. 
    940940      # * <tt>:conditions</tt>  - specify the conditions that the associated object must meet in order to be included as a "WHERE" 
    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" 
     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" 
    943943      # * <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 one 
    945       # * <tt>:delete_sql</tt> - overwrite the default generated SQL used to remove links between the associated  
    946       #   classes with a manual one 
    947       # * <tt>:insert_sql</tt> - overwrite the default generated SQL used to add links between the associated classes 
    948       #   with a manual one 
     944      # * <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 
    949949      # * <tt>:extend</tt>  - anonymous module for extending the proxy, see "Association extensions". 
    950950      # * <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 BY SQL-clause. 
     951      # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the "GROUP BY" SQL-clause. 
    952952      # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned. 
    953953      # * <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. 
    954954      # * <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