Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete_all with associations #27

Closed
iffyuva opened this issue Jan 2, 2015 · 5 comments · Fixed by #211
Closed

delete_all with associations #27

iffyuva opened this issue Jan 2, 2015 · 5 comments · Fixed by #211

Comments

@iffyuva
Copy link

iffyuva commented Jan 2, 2015

i have upgraded from rails 4.0.2 to 4.1.8, and i'm facing this issue with associations

class Reservation < AR::Base
  has_many :bookings
end

class Booking < AR::Base
  acts_as_paranoid

  belongs_to :reservation
end

r = Reservation.create(params)
b = Booking.create(reservation: r)

# does not work. does not set deleted_at to some Time.
# sql that im seeing is:
#  UPDATE "bookings" SET "reservation_id" = NULL WHERE
#    ("bookings"."deleted_at" IS NULL) AND 
#    "bookings"."reservation_id" = $1  [["reservation_id", 1]]
r.bookings.delete_all

# works, sets deleted_at to proper value.
# sql that im seeing is:
# UPDATE "bookings" SET "deleted_at" = '2015-01-02 13:07:06.374754' WHERE
#    ("bookings"."deleted_at" IS NULL) AND "bookings"."id" IN (1)
Booking.where(id: r.bookings.map(&:id)).delete_all

is this a known issue?

@zzak
Copy link
Contributor

zzak commented Oct 28, 2015

@iffyuva Does this issue still affect you on the latest version?

@iffyuva
Copy link
Author

iffyuva commented Oct 28, 2015

@zzak you mean on rails 4.2.4 ?

@zzak
Copy link
Contributor

zzak commented Oct 28, 2015

@iffyuva The latest version of acts_as_paranoid: https://rubygems.org/gems/acts_as_paranoid/versions/0.5.0.beta2

@zzak
Copy link
Contributor

zzak commented Jul 8, 2016

In fact, this seems like the current behavior from what I can see by the tests:
https://github.com/ActsAsParanoid/acts_as_paranoid/blob/master/test/test_relations.rb#L112

For example:

@paranoid_forest_2.paranoid_trees.order(:id).delete_all!

and

@paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)

For whatever reason, we must do this.

You could simplify your code to just r.bookings.order(:id).delete_all, I believe.

So perhaps this could be improved in the documentation.

@zzak zzak added this to the 0.5.0.rc1 milestone Jul 8, 2016
@zzak zzak modified the milestones: 1.0.0, 0.5.0.rc2 Mar 19, 2017
@mvz mvz closed this as completed in #211 Apr 23, 2021
@mvz
Copy link
Contributor

mvz commented Apr 23, 2021

As far as I can tell this problem no longer occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants