This project is archived and is in readonly mode.
has_many association proxy delete method sometimes deletes too liberally
-
Neeraj Singh
I am not able to reproduce this case with rails3 edge.
class Car < ActiveRecord::Base has_many :brakes def self.lab Car.create(:name => 'John') car = Car.last brakes = car.brakes brake = brakes.create(:name => 'wow') puts "brake id is #{brake.id}" brakes.build(:name => 'cursed brake') brakes.each do |brake| puts "processing brake #{brake.name}" car.brakes.delete(brake) end end endThe output of Car.lab is
SQL (0.4ms) INSERT INTO "cars" ("name") VALUES ('John')
Car Load (0.3ms) SELECT "cars". FROM "cars" ORDER BY cars.id DESC LIMIT 1 SQL (0.4ms) INSERT INTO "brakes" ("car_id", "name") VALUES (8, 'wow') brake id is 13
SQL (0.5ms) INSERT INTO "brakes" ("car_id", "name") VALUES (8, 'airblad') Brake Load (0.3ms) SELECT "brakes". FROM "brakes" WHERE ("brakes".car_id = 8) processing brake wow
SQL (0.3ms) UPDATE "brakes" SET "car_id" = NULL WHERE ("brakes"."car_id" = 8 AND "brakes"."id" IN (13)) processing brake cursed brake
=> [#]Everything looks okay to me.
-
Ryan Bigg
- Tag changed from activerecord associations to activerecord associations, bugmash
- State changed from new to incomplete
Please provide a failing test case and patch for this issue.
-
Neeraj Singh
- Importance changed from to Low
@Gabe Let's say that I have added a new record to collection using build. Now I want to delete that record. All I have to do is collection.delete(record) and then new object previously added to collection gets deleted. This behavior looks okay to me.
If your proposal is accepted then how would anyone delete any new record from collection?
-
Gabe da Silveira
Actually I wasn't proposing anything, what I was experiencing was a straight-up bug. However, I eventually tracked this down to a condition in my application, so there is in fact no bug here. Please make this ticket invalid.
-
Neeraj Singh
- State changed from incomplete to invalid
-
Rohit Arondekar
- Tag changed from activerecord associations, bugmash to activerecord, associations, bugmash