Panda Beer wrote:> Hi all ,
> I have a habtm relation between 2 tables:
> - users
> - rights
>
> 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:
> - "Joooooo"
> - "Jeannnn"
> - "Tommmm"
> # in Right model this:
> - "Write"
> - "Read"
> # 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
> "Write").
Perhaps something like:
class Right
after_destroy do
User.find(:all, :uniq => true, :joins => :rights,
:conditions => ''rights.id is
NULL'').each(&:destroy)
end
end
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---