aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/belongs_to_association.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-22 20:05:42 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-22 20:05:42 +0000
commit34f9d30e399050e776263441ee1d4415d0b2c254 (patch)
tree104acd17ac26f01436de6149e374ed9b43205e06 /activerecord/lib/active_record/associations/belongs_to_association.rb
parentea8f3f0a3765883c993cdd1c28ae958f097d2632 (diff)
downloadrails-34f9d30e399050e776263441ee1d4415d0b2c254.tar.gz
rails-34f9d30e399050e776263441ee1d4415d0b2c254.tar.bz2
rails-34f9d30e399050e776263441ee1d4415d0b2c254.zip
Added support for calling constrained class methods on has_many and has_and_belongs_to_many collections #1764 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1894 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/belongs_to_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index b142a13153..60c31ce486 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -1,6 +1,12 @@
module ActiveRecord
module Associations
class BelongsToAssociation < AssociationProxy #:nodoc:
+
+ def initialize(owner, association_name, association_class_name, association_class_primary_key_name, options)
+ super
+ construct_sql
+ end
+
def reset
@target = nil
@loaded = false
@@ -31,6 +37,9 @@ module ActiveRecord
return (@target.nil? ? nil : self)
end
+
+ protected
+
private
def find_target
@@ -48,9 +57,9 @@ module ActiveRecord
def target_obsolete?
@owner[@association_class_primary_key_name] != @target.id
end
-
+
def construct_sql
- # no sql to construct
+ @finder_sql = "#{@association_class.table_name}.#{@association_class.primary_key} = #{@owner.id}"
end
end
end