diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-10-02 10:52:55 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-10-02 10:52:55 -0300 |
commit | 29457a21c0d4451f5dbc66f72b8256baa02a55bd (patch) | |
tree | 50aebb7b31b990b805871e816b852151df2833a1 /activerecord/lib/active_record/associations | |
parent | 5f9540e4830ace3459b4018006573bad7fb30b53 (diff) | |
parent | 420004e030e96f2ace6e27fd622c90ee9e986677 (diff) | |
download | rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.tar.gz rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.tar.bz2 rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index c2568d0c0c..b85a40b2e5 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -8,18 +8,21 @@ module ActiveRecord def create(attrs = {}, replace_existing = true) new_record(replace_existing) do |reflection| + attrs = merge_with_conditions(attrs) reflection.create_association(attrs) end end def create!(attrs = {}, replace_existing = true) new_record(replace_existing) do |reflection| + attrs = merge_with_conditions(attrs) reflection.create_association!(attrs) end end def build(attrs = {}, replace_existing = true) new_record(replace_existing) do |reflection| + attrs = merge_with_conditions(attrs) reflection.build_association(attrs) end end @@ -128,6 +131,12 @@ module ActiveRecord inverse = @reflection.inverse_of return !inverse.nil? end + + def merge_with_conditions(attrs={}) + attrs ||= {} + attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) + attrs + end end end end |