Retrieving deleted entries

17 views
Skip to first unread message

Mateusz Wielgos

unread,
Aug 18, 2012, 12:10:13 PM8/18/12
to datam...@googlegroups.com
Hi,

How can I retrieve all deleted entries for a has_n relationship? 

I have a "Dealer" model. A dealer can have "n" number of coupons ("Coupon" model). Coupon model has a ParanoidDateTime property.

Doing:
Dealer.first(:id => 30000).coupons.with_deleted
Doesn't work. It gives me all coupons in the database. (Is this a possible bug?)

Doing:
Dealer.first(:id => 30000).coupons(:deleted_at.not => nil)
Doesn't work. It gives me an empty array. (With and without lazy load on :deleted_at)

The only way that I can make this to work is by doing the following:
Coupon.with_deleted.all(:dealer_id => 30000) - Coupon.all(:dealer_id => 30000)
If this is not self explanatory - getting all coupons for a said dealer and subtracting all currently active coupons.

This is very ugly. Anyone have any ideas?

Thanks for the help!!! :)
Reply all
Reply to author
Forward
0 new messages