On Thu, 22 Jan 2009 13:21:39 +0900
Makoto Kuwata <[email protected]> wrote:

> 
> Hi,
> 
> I have a question about Paranoid of DataMapper.
> I'm using Paranoid. It is great and very useful for me.
> But it seems that 'destroy!' doesn't submit UPDATE statement
> instead of DELETE.
> 
> For example:
> 
>   class Book
>     include DataMapper::Resource
>     property :id, Serial
>     property :title, String, :nullable => false
>     property :deleted_at, DataMapper::Types::ParanoidDateTime
>   end
> 
>   Book.first(:id=>1).destory
>       #=> UPDATE `books` SET `deleted_at` = '2009-01-22 13:16:36'
> WHERE (`id` = 1)
> 
>   Book.all.destroy!
>       #=> DELETE FROM `books` WHERE (`deleted_at` IS NULL)
> 
> 
> I want to 'Book.all.destroy!' to submit UPDATE statement
> instead of DELETE.
> Is it possible? Or should I define 'paranoind_destroy!' method
> into somewhere?
> 
> --
> regards,
> makoto kuwata
> 

Hi

This behaviour is unlikely to change in dm-core.  The bang methods (update!, 
destroy! etc.) are intended to work bypassing callbacks and other such things, 
operating directly on the table.  This is the why they have a bang.  Eventually 
the plan is to have each level (Model, Collection, Resource) responding to both 
destroy and destroy!, update and update! etc, with the normal method respecting 
callbacks and the bang method just operating directly.

You could replace all instances of destroy! with update!(:deleted_at => 
DateTime.now), or write a method, your paranoid_destroy!, which does that under 
the hood. 

Regards
Jon

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to