This project is archived and is in readonly mode.
2.1.0 has_many associations broken
Reported by Pavel Golubeff | June 21st, 2008 @ 06:51 PM
I don't like the solution to reload. Why not just set the instance var where AR updates the foreign key ?
Thanks.
Comments and changes to this ticket
-
Pavel Golubeff June 20th, 2008 @ 03:13 PM
- no changes were found...
-
Pavel Golubeff June 19th, 2008 @ 10:03 AM
I attached a simple example illustrating the problem. There are two models Post and Comment, and a test case, prooving a bug.
Actually the problem occurs, because << does not call reload on associated object and does not get changed owner. So, in my perception, if << reload object, everything would be fine.
-
Pavel Golubeff June 19th, 2008 @ 09:13 AM
I've got an addition. The problem occurs only in test environment.
-
Pavel Golubeff June 18th, 2008 @ 07:41 PM
Hi there.
After installing 2.1.0 rails gem i experience problem with has_many associations.
It's impossible to change object owner, if it has one already.
For example:
user1 = User.create
>> #<User id: 1>
user2 = User.create
>> #<User id: 2>
char = Character.create( :user => user1 )
>> #<Character id:1, :user_id => 1>
user2.characters << char
char.user_id
>> 1
As far as i'm concirned, breaking code is situated in active_record/associations.rb, line 898, where belongs_to_before_save_for_#{reflection.name} is defined.
association is taken from char.instance_variable_get("@user") and in case it is defined, it executes char[:user_id] = @user.id.
Commenting this line make everyone happy, but i'm not sure, if it's a good idea:
- self["#{reflection.primary_key_name}"] = association.id
-
Prem Sichanugrist (sikachu) January 22nd, 2010 @ 08:53 AM
- State changed from new to stale
- Tag set to 2.1, activerecord, bug, edge, has_many, patch, tested
- Assigned user set to Pratik
-
Pratik January 22nd, 2010 @ 10:28 AM
- State changed from stale to invalid
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>