This project is archived and is in readonly mode.
Size of through association is not correct after adding a has_many association
Reported by Jason Cheow | November 14th, 2010 @ 06:12 AM
With the following:
class Post < ActiveRecord::Base
has_many :readers
has_many :people, :through => :readers
end
class Person < ActiveRecord::Base
has_many :readers
has_many :posts, :through => :readers
end
class Reader < ActiveRecord::Base
belongs_to :post
belongs_to :person
end
post = Post.create
post.people << Person.create
post.readers.size # Returns 2, when 1 is expected.
post.reload.readers.size # Returns 1 as expected.
This happens because ActiveRecord::Associations::HasManyThroughAssociation#insert_record has an extraneous line that adds the same through record after creating it.
A patch with a failing test and the fix is attached.
Comments and changes to this ticket
-
Repository November 14th, 2010 @ 05:37 PM
- State changed from new to committed
(from [93c9f4a942c622ecbe8d46ab4838bd072aef9fc0]) Fix bug where size of through association is not correct after adding a has_many association (occurs only before main object has been reloaded).
[#5968 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/93c9f4a942c622ecbe8d46ab4838b... -
Repository November 14th, 2010 @ 05:38 PM
(from [f8b7c74f9b7b0e9b76c03953275d98378cb1d139]) Fix bug where size of through association is not correct after adding a has_many association (occurs only before main object has been reloaded).
[#5968 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/f8b7c74f9b7b0e9b76c03953275d9...
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>
People watching this ticket
Attachments
Referenced by
- 5968 Size of through association is not correct after adding a has_many association [#5968 state:committed]
- 5968 Size of through association is not correct after adding a has_many association [#5968 state:committed]