search for: association_proxy_class

Displaying 3 results from an estimated 3 matches for "association_proxy_class".

2008 May 07
1
Assigning to the foreign key on a belongs_to association
...sociations.rb index 0809b27..7135e50 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1094,6 +1094,13 @@ module ActiveRecord instance_variable_set(ivar, new_value.nil? ? nil : association) end + if association_proxy_class == BelongsToAssociation + define_method("#{reflection.primary_key_name}=") do | target_id| + instance_variable_set(ivar, nil) + self["#{reflection.primary_key_name}"] = target_id + end + end + define_method(&quo...
2007 Nov 12
1
Possible bug
...many if options[:through] collection_reader_method(reflection, HasManyThroughAssociation) <--- FIRST CALL collection_accessor_methods(reflection, HasManyThroughAssociation, false) <-- CALLED AGAIN INSIDE THIS METHOD else .... def collection_accessor_methods(reflection, association_proxy_class, writer = true) collection_reader_method(reflection, association_proxy_class) <-- SECOND CALL WITH SAME ARGUMENTS .... Looks like collection_reader_method is being called twice with the same arguments. Bob Silva --~--~---------~--~----~------------~-------~--~----~ You received th...
2007 May 10
0
Counterintuitive behavior in ActiveRecord I was implementing dirty checking for an application, and I found something that is a little counterintuitive. Let me start with a quick quiz: bob=User.find(1) alice=User.find(2) trip=Trip.new trip.driver=bob old_
...Alice, you''re right. Inside associations.rb, the mutator is defined as: define_method("#{reflection.name}=") do |new_value| association = instance_variable_get("@#{reflection.name}") if association.nil? association = association_proxy_class.new(self, reflection) end association.replace(new_value) By re-using the proxy, we get this odd assignment behavior. Is there any reason not to create a new proxy on assignment? Simply eliminating the if condition fixes my case, and all tests still pass. I can cr...