aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorjosevalim <jose.valim@gmail.com>2008-05-23 11:20:13 +0200
committerMichael Koziarski <michael@koziarski.com>2008-05-24 17:58:03 +1200
commit8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be (patch)
tree06a4ff2e8bbb4646082fd627ed6633d79a4ee949 /activerecord/lib
parent5b8d0f134a5766aa1b3d0945b79f04d2bb911c02 (diff)
downloadrails-8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be.tar.gz
rails-8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be.tar.bz2
rails-8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be.zip
Added :select option to has_one and belongs_to, remove unused :order option on belongs_to.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#241 state:resolved]
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x[-rw-r--r--]activerecord/lib/active_record/associations.rb16
-rwxr-xr-x[-rw-r--r--]activerecord/lib/active_record/associations/belongs_to_association.rb5
-rwxr-xr-x[-rw-r--r--]activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb5
-rwxr-xr-x[-rw-r--r--]activerecord/lib/active_record/associations/has_one_association.rb5
4 files changed, 18 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 95caf68692..6c21fed8ea 100644..100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -667,7 +667,7 @@ module ActiveRecord
# * <tt>:limit</tt> - An integer determining the limit on the number of rows that should be returned.
# * <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.
# * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, 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.
# * <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
# * <tt>:through</tt> - Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
# are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a <tt>belongs_to</tt>
@@ -747,6 +747,8 @@ module ActiveRecord
# as the default <tt>:foreign_key</tt>.
# * <tt>:include</tt> - Specify second-order associations that should be eager loaded when this object is loaded.
# * <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
+ # * <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
+ # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
# * <tt>:through</tt>: Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
# are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a
# <tt>has_one</tt> or <tt>belongs_to</tt> 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.
# * <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
# SQL fragment, such as <tt>authorized = 1</tt>.
- # * <tt>:order</tt> - Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
- # such as <tt>last_name, first_name DESC</tt>.
+ # * <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
+ # but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
# * <tt>:foreign_key</tt> - 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 <tt>belongs_to :person</tt> association will use
# "person_id" as the default <tt>:foreign_key</tt>. Similarly, <tt>belongs_to :favorite_person, :class_name => "Person"</tt>
@@ -1011,7 +1013,7 @@ module ActiveRecord
# * <tt>:limit</tt> - An integer determining the limit on the number of rows that should be returned.
# * <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.
# * <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
- # 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.
# * <tt>:readonly</tt> - 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
)
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 9ff3f13592..7c28cbdd07 100644..100755
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -42,10 +42,11 @@ module ActiveRecord
private
def find_target
@reflection.klass.find(
- @owner[@reflection.primary_key_name],
+ @owner[@reflection.primary_key_name],
+ :select => @reflection.options[:select],
:conditions => conditions,
:include => @reflection.options[:include],
- :readonly => @reflection.options[:readonly]
+ :readonly => @reflection.options[:readonly]
)
end
diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
index 9549b959fc..df4ae38f38 100644..100755
--- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
@@ -29,12 +29,13 @@ module ActiveRecord
if @reflection.options[:conditions]
association_class.find(
- @owner[@reflection.primary_key_name],
+ @owner[@reflection.primary_key_name],
+ :select => @reflection.options[:select],
:conditions => conditions,
:include => @reflection.options[:include]
)
else
- association_class.find(@owner[@reflection.primary_key_name], :include => @reflection.options[:include])
+ association_class.find(@owner[@reflection.primary_key_name], :select => @reflection.options[:select], :include => @reflection.options[:include])
end
end
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index 3ff9fe3b9f..c2b3503e0d 100644..100755
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -51,10 +51,11 @@ module ActiveRecord
private
def find_target
@reflection.klass.find(:first,
- :conditions => @finder_sql,
+ :conditions => @finder_sql,
+ :select => @reflection.options[:select],
:order => @reflection.options[:order],
:include => @reflection.options[:include],
- :readonly => @reflection.options[:readonly]
+ :readonly => @reflection.options[:readonly]
)
end