This project is archived and is in readonly mode.
[Patch] has_many :through doesn't update counter_cache on join model correctly.
If you have a counter_cache on a join model used in a has_many :through association, when removing items from the association, the counter_cache doesn't get decremented correctly. e.g.
class Post < ActiveRecord::Base has_many :taggings has_many :tags, :through => :taggings end class Tagging < ActiveRecord::Base belongs_to :post, :counter_cache => true belongs_to :tag end class Tag < ActiveRecord::Base has_many :taggings has_many :posts, :through => :taggings end post = Post.create!() tag1 = Tag.create!() tag2 = Tag.create!() post.tags << tag1 post.reload.taggings_count # => 1 post.tags = [tag2] post.reload.taggings_count # => 2 ! Should be 1
This happens because #delete_records in HasManyThroughAssociation does a delete_all. The attached patch changes this to a destroy_all which fixes the issue.
Comments and changes to this ticket
Unfortunately this patch does not apply cleanly for me.
It comes up with an error message
Applying Make has_many :through update counter_cache on join model correctly. error: patch failed: activerecord/test/cases/associations/has_many_through_associations_test.rb:81 error: activerecord/test/cases/associations/has_many_through_associations_test.rb: patch does not apply Patch failed at 0001. When you have resolved this problem run "git-am --resolved". If you would prefer to skip this patch, instead run "git-am --skip".
That works fine and updates taggings_count as expected.
This problem exists in edge rails as well. Is this change going to be somehow merged back there or patch needs to be created to deal with this issue in edge rails?
Don't be sorry Alex. It is me who didn't notice 2-3-stable in the tags for this ticket but I am very new to lighthouse and as a matter of fact to rails itself as well (and git :).
Ok, patches done. They're on github here: http://github.com/unboxed/rails/tree/2-3-counter-cache-fix and here: http://github.com/unboxed/rails/tree/edge-counter-cache-fix
Let me know if you'd prefer me to create actual patch files for these.
- Title changed from [Patch] has_many :through doesn't update counter_cache on join model correctly. to [PATCH] Clean up "omg" comments
- Assigned user cleared.
- Tag changed from rails 3, 2-3-stable, bug, bugmash, counter_cache, has_many_through, patch to 3, documentation, patch, review
On a certain cheap timberland boots day at a certain hour, we will pull into the station. Bands will be playing and flags discount timberland boots waving. Once we get there, so many wonderful timberland winter boots dreams will come true and the pieces of our lives will fit together like a completed jigsaw puzzle. How restlessly we pace the aisles, womens timberland boot the minutes for loitering --waiting, waiting, waiting for the station.But uppermost in our timberland shoes store minds is the final destination. On a certain day at a certain hour, we will pull into the station. Bands will be playing and timberland eye boat flags waving. Tucked away in our timberland for you subconscious is an idyllic vision. We see ourselves on a long trip that timberland 6 inch spans the continent. We are traveling by train. Out timberland hiking boots windows, we drink in the passing scene of cars on nearby highways, of children timberland shoe company waving at a crossing, of cattle grazing on a distant timberland boots hillside, of smoke pouring from a power plant, of row upon row of corn and wheat, of flatlands and timberland wheat shoes valleys, of mountains and rolling classic 3 eye timberland boat hillsides, of city skylines and village halls.But uppermost in our black timberland boots minds is the final destination.
- Title changed from [PATCH] Clean up "omg" comments to [Patch] has_many :through doesn't update counter_cache on join model correctly.
- Assigned user set to Yehuda Katz (wycats)
- Tag changed from 3, documentation, patch, review to rails 3, 2-3-stable, bug, bugmash, counter_cache, has_many_through, patch
Reverting Spam changes...
I hit the same problem, using rails 2.3.
I identified another issue, look at this code:
class PlaylistTrack < ActiveRecord::Base belongs_to :playlist, :counter_cache => true, :touch => true belongs_to :track
1) adding an object to the collection using <<
- counter cache works
- playlist.updated_at fields gets correctly updated
2) **removing an object from the collection using collection.delete(object)
- counter cache won't work
- playlist.updated won't get updated
In the end there might be additional issues because Playlist might have an observer/callback that runs after_update code.
In the point 1 this after_update is not triggered by the rails code that updates the counter_cache, but from the :touch one, meaning that adding the :touch options also triggers correctly after_update callbacks.
Luckily it won't fire twice.
However in the point 2 since nothing is run also the after_update callback isn't run.
Any plans to integrate this patch please?
Otherwise, the jewelry would be faded. Third, ladies had better go to jewelry shop to check and clean at least once a year. http://www.tiffanyjewellerypalace.com/
Fourth, put away the diamond jewelry well. Diamond jewelry should be separated from other decorations, for other decorations may cut the diamond.
The current status of the has_many_through association and its dependent options is the following:
# TODO - add dependent option support def delete_records(records)
Also in the reference one can find this line:
Warning: This option is ignored when used with :through option.
I've implemented the method, and it works for me prerry well. Could anyone please test the attached patch? It turned out that it's rather hard to run the whole tests of active record...
cheap ugg boots, cheap uggs, cheap uggs the only boot sale, uggs for cheap, cheap ugg, ugg boots cheap, cheap kids uggs, cheap classic tall ugg boots 5815 mulberry, uggs cheap, uk cheap ugg boots, super cheap ugg classic mini boots, cheap ugg boots with zips, cheap ugg sunburst boots, really cheap ugg classic mini, cheap ugg boots for $64, ugg boots for cheap, ugg slippers cheap, cheap authentic uggs,
cheap ugg boots for sale in uk, cheap ugg boots mulberry So You Can Buy It Now!
ugg boots, cheap ugg boots, ugg boots on sale, ugg brand boots, ugg boots uk, ugg boots sale, ugg australia boots, discount ugg boots, what stores sell ugg boots, ugg boots on sale authorized, us ugg boots, mens ugg boots, australian ugg boots, ugg cove boots, fur inside ugg boots, kids ugg boots, ugg bailey boots, adirondack tall ugg boots, shopping for ugg boots, ugg mini boots, womens ugg boots, lowest price ugg boots, baby ugg boots, ugg style boots, knock off ugg boots, ugg boots discount, ugg cove boots sale, discounted ugg boots, ugg roseberry boots, purple ugg boots, ugg boots sydney, ugg boots cheap, ugg boots store SO Cheap With Free Shipping!
UGG Store, UGG Store Outlet, UK UGG Store, ugg factory store, ugg outlet stores, what stores sell ugg boots, ugg outlet store locations in pa hit bg, ugg store, ugg boots store, shoe stores ugg australia sandals kids, boot shoes store ugg hit bg, ugg store locater, shoe stores ugg australia kids Thats ugg store uk online shop!
ugg boots, tall boots, cardy ugg boots, uggs sale, classic cardy ugg, ugg classic cardy, ugg cardy, ugg cardy boots on sale, ugg classic cardy boots, ugg cardy chocolate, ugg cardy sale, ugg classic cardy tall, ugg boots cardy, classic cardy ugg boots, classic cardy ugg boots cream, ugg cardy boot, ugg cardy boots, adirondack tall ugg boots, ugg classic tall boots, ugg classic tall, ugg mosaic tall, ugg tall boot sale, cheap classic tall ugg boots 5815 mulberry, classic tall ugg boots, ugg classic tall boot, ugg classic cardy tall, sundance tall ugg boots, ugg boots classic tall, ugg adirondack tall, ugg classic tall wool. Have You Best Choice, Buy It Now!
UGG Classic Short, UGG Short Boots, Short uggs, UGG Shop online, authentic ugg australia women's classic short #5825 - black sheepskin,
ugg classic short boots, ugg fern suede classic short, classic short ugg boots, classic short ugg in grey, ugg short boots fushia, ugg boots 8 short, ugg ultra short black, eggplant short ugg, short classic ugg boots, short ugg boots chestnut womens, ugg boots black short, ugg classic short black paisley, ugg classic short boot, ugg ultra short sku, ugg women's classic short, Buy It Now!
UGG Bailey Button, UGG Bailey Button Boots, UGG Bailey Button Triplet, UGG Bailey Button Bomber, UGG Boots 5803, UGG Boots 1873, UGG Boots USA, bailey button ugg boots, ugg bailey button boots bomber, ugg bailey button boot, ugg bailey button boots at macys, ugg boots - bailey button novelty- kids grey, ugg australia bailey button, ugg bailey button crinkle leather, ugg bailey button boots on sale, ugg bailey button triplet boot, ugg bailey button blackberry wine, discount ugg bailey button, ugg australia bailey button boots, ugg bailey button 5803 grey size 10, ugg bailey button boot grey, ugg bailey button cheap, ugg bailey button triple, ugg boots - bailey button novelty, Buy It Now!
I apply the path to the branch 3.0-stable (3.0.4rc)
class User < ActiveRecord::Base # need to provide an accessor , if not WARNING: Can't mass-assign protected attributes: role_ids attr_accessible :role_ids has_many :permissions has_many :roles, :through => :permissions end class Role < ActiveRecord::Base attr_accessible :name, :users_count has_many :permissions has_many :users, :through => :permissions end class Permission < ActiveRecord::Base belongs_to :role, :counter_cache => true belongs_to :user end
When i try to update my model (in a controller ) with
i got this error
update'<br/> rails.3.0.4rc/activerecord/lib/active_record/associations/has_many_through_association.rb:95:inblock in delete_records'
block in delete'<br/> rails.3.0.4rc/activerecord/lib/active_record/associations/association_collection.rb:525:inblock in remove_records'
block in transaction'<br/> rails.3.0.4rc/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:139:intransaction'
block in replace'<br/> rails.3.0.4rc/activerecord/lib/active_record/associations/association_collection.rb:158:inblock in transaction'
block in collection_accessor_methods'<br/> rails.3.0.4rc/activerecord/lib/active_record/associations.rb:1532:inblock in collection_accessor_methods'
block in attributes='<br/> rails.3.0.4rc/activerecord/lib/active_record/base.rb:1554:ineach'
attributes='<br/> rails.3.0.4rc/activerecord/lib/active_record/persistence.rb:127:inblock in update_attributes'
block in with_transaction_returning_status'<br/> rails.3.0.4rc/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:139:intransaction'
update_attributes'<br/> app/controllers/admin/users_controller.rb:141:inblock in update'
Happiness is accompanied by ugg boots sale sorrow, and it would turn discount ugg boots sunny after rain as well. If rain remains after rain and sorrow ugg boots remains after sorrow, please take those ugg australia boots farewells easy, and turn to smilingly look for yourself who is never to appear http://www.topuggworld.com/ .
Happiness christian louboutin sale is like a pebble dropped into a christian louboutin pool to set in motion an ever-widening circle of christian louboutin shoes ripples. As Stevenson has said christian louboutin boots, being happy is a tory borch shoes duty. There is no exact definition of the http://www.christianlouboutinshoestore.com/ word happiness.
Maybe God wants us to meet cheap ed hardy clothing sale a few wrong people before meeting the right womens ed hardy clothing one, so that when we finally meet the ed hardy online shop person, we will know how to be grateful ed hardy clothing .Do not cry because it is mens moncler jackets over, smile because it happened http://www.edhardy-buy.com/ .
I would not care success christian louboutin shoes or failure, for I will only struggle louboutin sale ahead as long as I have been destined to the discount christian louboutin shoes distance. I would not care the christian louboutin booties difficulties around, for what I can leave on the christian louboutin boots earth is only their view of my back since I have been marching toward the http://www.louboutinszone.com/ horizontal.
The tragedy of louboutin shoes life is not so much what men suffer, but what christian louboutin sale they miss. I find life an exciting christian louboutin shoes business and most exciting when it is lived for discount christian louboutin others. Young men make great mistakes in christian louboutin pumps life for one thing, they idealize love http://www.louboutinsonline.com/ too much.
Nobody can look into this issue i m really stuck !
Thanks in advance.
look my previous stackstrace:
rails.3.0.4rc/activerecord/lib/active_record/associations/has_many_through_association.rb:95:inblock in delete_records'
rails.3.0.4rc/activerecord/lib/active_record/associations/association_collection.rb:222:in block in delete'
rails.3.0.4rc/activerecord/lib/active_record/associations/association_collection.rb:525:inblock in remove_records'
rails.3.0.4rc/activerecord/lib/active_record/associations/association_collection.rb:158:in block in transaction'
Kids Ugg Boots 5991ugg boots clearance nike air max 902010 New Ugg UGG Tassel Short Ugg Classic Crochet 5833 UGG Roxy Tall 5818 Ugg Ultra Short Ugg Classic Tall Stripe Cable Knit Ugg Classic Metallic Ugg Classic Argyle Knit Ugg Infants Erin Ugg Classic Mini Ugg Classic Short Ugg Classic Cardy Ugg Classic Tall Ugg Sundance II Ugg Ultra Tall Ugg Nightfall Ugg Classic Tall Romantic Flower Ugg Bailey Button Ugg Slippers Ugg Handbags Ugg Casuals Ugg Sandals Ugg Ashur Tall Boots Ugg Delaine 1886 Ugg Coquette Slippers 5125 Ugg Original Sundance 5605 UGG Bailey Button Krinkle 1873 Ugg MetalicFancy Bailey Button 5809 UGG Adirondack Short Boots 5469 UGG Adirondack Boots II 5498 UGG Fringe Cardy Boots 1878 Ugg Kensington Boots 5678 Ugg Kona Boots 5181 Ugg Sienna Miller Boots 5816 Ugg Scarves UGG Sunburst Tall Boots 5218 Ugg Ultimate Tall Braid Boots 5340 UGG Ultimate Short 5275 UGG Felicity Boots 5450 UGG Stella Boots 5453 Ugg Broome Boots 5511 Ugg Gissella Boots 5593 UGG Brookfield Tall Boots 5594 UGG Elsey Boots 5596 UGG Suburb Crochet Tall 5733 UGG Roseberry Boots 5734 UGG Tall Baroque 5852 UGG Gloves Ugg Jimmy Choo Boots 3042 Ugg Classic Tall 5815 Ugg Classic Tall Nike Air Max 24 7 Men Nike Air Max 24 7 Womens Nike Air Max 2009 Men Nike Air Max 2009 Kids Nike Air Max 2009 Womens Nike Air Max 2010 Men Nike Air Max 2010 Womens Nike Air Max 2011 Men Nike Air Max 2011 Womens Nike Air Max 2012 Nike Air Max Classic Bw Nike Air Max TN Ⅲ Nike Air Max Ltd Men Nike Air Max Ltd Womens Nike Air Max Ltd 2 Nike Air Max TN Men Nike Air Max TN Kids Nike Air Max TN Women Nike Air Max TN 8 Men Nike Air Max TN 10 Men Nike Air Max Classic BW Women Nike Air Max Preview Men Nike Air Max 2Fal Men Nike Air Max 2Fal Womens Nike Air Max 90
- State changed from open to resolved
(from [52f09eac5b3d297021ef726e04ec19f6011cb302]) Correctly update counter caches on deletion for has_many :through [#2824 state:resolved]. Also fixed a bunch of other counter cache bugs in the process, as once I fixed this one others started appearing like nobody's business. https://github.com/rails/rails/commit/52f09eac5b3d297021ef726e04ec1...
Good Puma shoes sale information for Puma shoes fans: Yesterday, German sportswear maker Cheap Running Shoes purchased effectively lot of money Brands. The transaction entails the Cobra brand, too as linked inventory, intellectual house and endorsement contracts. It also helps make puma speed cat Shoes . They provide you with the utmost game and support all through the feet.You can happen around several types of basketball sneakers such as high-top,low-top and mid-top.The Puma shoes online and boots give you best ankle support will support want you to obtain steadiness.
As we konw,Trail Puma Drift Cat Shoes black, Trail Puma future cat ShoesWhite Black? 50 many years backshore are actually released within a great accomplishment. Trail Running Shoes speed cat shoes?go in add-on to King Pele into planet tournament finals, bottom tennis discs matchrs within pasture inhabit an vital area in hold out in Wimbledon Dun; Its working firms have premier manufacturers and major marketplace positions in distilled spirits, residence and security, and golf products. The reply go all through the Cheap puma shoes on sale-here you are able to happen around several distcoun.puma shoes on sale .
Apologies if this is not the correct place to post this but I would like some advice on the best way to integrate this in my project.
I am currently using rails 3.0.5 rather than rails edge.
Should I change my gemfile to point to the git repository as I am deploying to heroku.
Or is there an alternative? Perhaps cloning the git repository and manually copying the new files over?
Or do I make a patch for 3.0.5?
Apart from this functionality I am more than happy with everything else and thank you so much for all the hard work.
Sorry about this being a n00b question and if there is an FAQ or similar I have missed with this information then I apologise.
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>