tjholowaychuk,

You need to destroy the intermediate collection not the target one. So
if your setup is something like this:

User.has(n, :role_memberships)
User.has(n, :roles, :through => :role_memberships)

You need to do

user = User.get(params[:id])
user.role_memberships.destroy if user

This will delete all all role associations for the given user, leaving
the user and the roles themselves intact.

If you happen to have

User.has(n, :roles, :through => Resource)

Then I'm pretty sure you would need to do

user = User.get(params[:id])
user.user_roles.destroy if user

This will again only delete the intermediate resources, leaving source
and target intact.

Hope that helps
snusnu

On Mon, Aug 17, 2009 at 20:18, tjholowaychuk<[email protected]> wrote:
>
> I have User and Role models, and I want to remove the association, but
> the role is still available to other users..
>
> User.first(:id => params[:id].to_i).roles.delete_if {} ... ?
> destroy! ?  the documentation is not very clear with this, thanks!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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