This project is archived and is in readonly mode.
reset_counters doesn't work with polymorphic associations
-
Neeraj Singh
- State changed from new to open
- Importance changed from to Low
I am attaching a patch with test which does not solve the original problem. However it is a step in that direction.
Currently following works
class Car < ActiveRecord::Base has_many :brakes end class Brake < ActiveRecord::Base belongs_to :car, :counter_cache => :count_of_items end Car.reset_counters 1, :brakesHowever following does not work
class Car < ActiveRecord::Base has_many :brakes end class Brake < ActiveRecord::Base belongs_to :my_car, :class_name => 'Car', :foreign_key => 'car_id', :counter_cache => :count_of_items end Car.reset_counters 1, :brakesAttached patch fixes this problem.
-
Neeraj Singh
- Tag changed from nested attributes, polymorphic, reset_counters to nested attributes, polymorphic, rails3, reset_counters
-
Santiago Pastorino
- Milestone cleared.
- Assigned user set to José Valim
-
José Valim
Neeraj, what do we need in order to have a complete fix? What is blocking it? Thanks! :)
-
Neeraj Singh
Right now I am not able to articulate what was blocking me. I will take a look at ticket again today and will update accordingly.
-
Neeraj Singh
- Tag changed from nested attributes, polymorphic, rails3, reset_counters to nested attributes, patch, polymorphic, rails3, reset_counters
Attached is patch with test.
-
Repository
- State changed from open to resolved
(from [1e53404fe9c39ad0849894d73e431315be8c0bf0]) reset_counter should work with non-traditional belongs_to and polymorphic belongs_to
[#4984 reset_counters doesn't work with polymorphic associations state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/1e53404fe9c39ad0849894d73e4313...
