Forum: Ruby on Rails has_and_belongs_to_many delete

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tarscher (Guest)
on 2007-02-03 21:45
(Received via mailing list)
Hi all,

I have a has_and_belongs_to_many relationship with 2 tables (users -
users_teams, teams)

Can I delete a user from a team with 1 function? I now first delete
the user from users_teams and then from teams. Can't this be done with
one method?

Thanks

Stijn
Josh S. (Guest)
on 2007-02-04 18:44
Tarscher wrote:

> I have a has_and_belongs_to_many relationship with 2 tables (users -
> users_teams, teams)
>
> Can I delete a user from a team with 1 function? I now first delete
> the user from users_teams and then from teams. Can't this be done with
> one method?

team.users.delete(user)

--
Josh S.
http://blog.hasmanythrough.com/
Tarscher (Guest)
on 2007-02-07 18:27
(Received via mailing list)
Hi, thanks for the reply

Though I still don't get it to work

When I do
    team = Node.find(teamid)
    user = User.find(userid)
    team.users.delete(user)

ActiveRecord only deletes records in the users_teams table and not
users table. Is this not possible with 1 function?

Thanks
Stijn
This topic is locked and can not be replied to.