Apologies if this has been asked before but I didn't find anything
searching the history.

I have a company model that uses ParanoidDateTime.  The company has
many child project records.  I want to add a before :destroy hook to
prevent the company from being deleted if it has child projects.  I
know there's an issue with before :destroy and ParanoidDateTime so I'm
using a before :update and checking if the deleted_at attribute is
ditry.

However, my current implementation always returns true after calling
destroy - even though it keeps the record from being deleted.  When
destroy is called, it returns true, but the record is not deleted and
the deleted_at attribute is not set - so it's still a live record -
why is destroy returning true?

Here's my code:

  before :update do
    ensure_not_in_use if attribute_dirty? :deleted_at
  end

  private
  def ensure_not_in_use
    throw :halt if self.projects.count > 0
  end

Company.first.destroy #=> true

Thanks,
Glen
--~--~---------~--~----~------------~-------~--~----~
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