radar (owner)

Revisions

gist: 219479 Download_button fork
public
Public Clone URL: git://gist.github.com/219479.git
Embed All Files: show embed
Diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index fab6359..93b2deb 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1532,6 +1532,7 @@ module ActiveRecord
         def create_has_many_reflection(association_id, options, &extension)
           options.assert_valid_keys(valid_keys_for_has_many_association)
           options[:extend] = create_extension_modules(association_id, extension, options[:extend])
+ options[:as] ||= self.class.to_s.underscore.to_sym
 
           create_reflection(:has_many, association_id, options, self)
         end
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 241b9bf..099b655 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -185,6 +185,7 @@ module ActiveRecord
               record[@reflection.primary_key_name] = @owner.send(primary_key)
             end
           end
+ record.send("#{@reflection.options[:as]}=", @owner)
         end
 
         # Merges into +options+ the ones coming from the reflection.