diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-05-05 10:14:28 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-05-05 10:14:28 -0300 |
commit | a83a1ccebaaae5e05741ebd5d9db408c450df098 (patch) | |
tree | 79dc5924ce11481674180e1d216ec6551e634011 /activerecord/lib/active_record/associations/belongs_to_association.rb | |
parent | d19d4d2f20d87289eaeaa8df807d635ce72f3799 (diff) | |
parent | d4402c5554a0d3202fc22eb38c5c1a8c4b9afd93 (diff) | |
download | rails-a83a1ccebaaae5e05741ebd5d9db408c450df098.tar.gz rails-a83a1ccebaaae5e05741ebd5d9db408c450df098.tar.bz2 rails-a83a1ccebaaae5e05741ebd5d9db408c450df098.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record/associations/belongs_to_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index f05c6be075..c88575048a 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -31,6 +31,8 @@ module ActiveRecord @updated = true end + set_inverse_instance(record, @owner) + loaded record end @@ -41,18 +43,26 @@ module ActiveRecord private def find_target - @reflection.klass.find( + the_target = @reflection.klass.find( @owner[@reflection.primary_key_name], :select => @reflection.options[:select], :conditions => conditions, :include => @reflection.options[:include], :readonly => @reflection.options[:readonly] ) + set_inverse_instance(the_target, @owner) + the_target end def foreign_key_present !@owner[@reflection.primary_key_name].nil? end + + # NOTE - for now, we're only supporting inverse setting from belongs_to back onto + # has_one associations. + def we_can_set_the_inverse_on_this?(record) + @reflection.has_inverse? && @reflection.inverse_of.macro == :has_one + end end end end |