From 8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be Mon Sep 17 00:00:00 2001 From: josevalim Date: Fri, 23 May 2008 11:20:13 +0200 Subject: Added :select option to has_one and belongs_to, remove unused :order option on belongs_to. Signed-off-by: Michael Koziarski [#241 state:resolved] --- activerecord/lib/active_record/associations.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) mode change 100644 => 100755 activerecord/lib/active_record/associations.rb (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb old mode 100644 new mode 100755 index 95caf68692..6c21fed8ea --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -667,7 +667,7 @@ module ActiveRecord # * :limit - An integer determining the limit on the number of rows that should be returned. # * :offset - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows. # * :select - By default, this is * as in SELECT * FROM, but can be changed if you, for example, want to do a join - # but not include the joined columns. + # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will rise an error. # * :as - Specifies a polymorphic interface (See belongs_to). # * :through - Specifies a Join Model through which to perform the query. Options for :class_name and :foreign_key # are ignored, as the association uses the source reflection. You can only use a :through query through a belongs_to @@ -747,6 +747,8 @@ module ActiveRecord # as the default :foreign_key. # * :include - Specify second-order associations that should be eager loaded when this object is loaded. # * :as - Specifies a polymorphic interface (See belongs_to). + # * :select - By default, this is * as in SELECT * FROM, but can be changed if, for example, you want to do a join + # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error. # * :through: Specifies a Join Model through which to perform the query. Options for :class_name and :foreign_key # are ignored, as the association uses the source reflection. You can only use a :through query through a # has_one or belongs_to association on the join model. @@ -821,8 +823,8 @@ module ActiveRecord # if the real class name is Person, you'll have to specify it with this option. # * :conditions - Specify the conditions that the associated object must meet in order to be included as a +WHERE+ # SQL fragment, such as authorized = 1. - # * :order - Specify the order in which the associated objects are returned as an ORDER BY SQL fragment, - # such as last_name, first_name DESC. + # * :select - By default, this is * as in SELECT * FROM, but can be changed if, for example, you want to do a join + # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error. # * :foreign_key - Specify the foreign key used for the association. By default this is guessed to be the name # of the association with an "_id" suffix. So a class that defines a belongs_to :person association will use # "person_id" as the default :foreign_key. Similarly, belongs_to :favorite_person, :class_name => "Person" @@ -1011,7 +1013,7 @@ module ActiveRecord # * :limit - An integer determining the limit on the number of rows that should be returned. # * :offset - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows. # * :select - By default, this is * as in SELECT * FROM, but can be changed if, for example, you want to do a join - # but not include the joined columns. + # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error. # * :readonly - If true, all the associated objects are readonly through the association. # # Option examples: @@ -1341,7 +1343,7 @@ module ActiveRecord def create_has_one_reflection(association_id, options) options.assert_valid_keys( - :class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly + :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly ) create_reflection(:has_one, association_id, options, self) @@ -1349,14 +1351,14 @@ module ActiveRecord def create_has_one_through_reflection(association_id, options) options.assert_valid_keys( - :class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type + :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type ) create_reflection(:has_one, association_id, options, self) end def create_belongs_to_reflection(association_id, options) options.assert_valid_keys( - :class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent, + :class_name, :foreign_key, :foreign_type, :remote, :select, :conditions, :include, :dependent, :counter_cache, :extend, :polymorphic, :readonly ) -- cgit v1.2.3