Panda Beer wrote:
Hi all ,
I have a habtm relation between 2 tables:
If there a way to affect a destroy dependance on those 2 tables only for
the last instance? In my opinion, dependent => :destroy is not the
solution because this delete all the linked instance.
For example, if I have:
# in User model this:
# in Right model this:
# in the habtm relation this:
- "Joooooo" can "Write"
- "Joooooo" can "Read"
- "Jeannnn" can "Read"
I would like to be able to delete "Read" in Right model, and automaticly
deleting "Jeannnn" user too, because this user have no other right. But
without deleting "Joooooo" user (because he remains have a right named
Perhaps something like:
User.find(:all, :uniq => true, :joins => :rights,
:conditions => 'rights.id is NULL').each(&:destroy)