views:

36

answers:

3

This is a lot harder in code, than in real life. =)
But anyway,
My Users have managers, and vice versa...

How do I remove the relationship?

@selected_user = User.find(params[:id])
@selected_user.managers.delete_if{|x| x.standard_user_id == params[:id].to_i}

This is a self referential has and belongs to many relationship, so I have another table that has only two columns of foreign keys, both pointing to the Users table. This lookup table does not have a model.

+1  A: 

Doesnt this work ? @selected_user.managers.each{|x| x.destroy!} or Managers.delete_all "standard_user_id = params[:id]"

NM
I should probably have added that it is a self referential has and belongs to many relationship
DerNalia
thing is, there isn't actually a column called managers or standard_users in the users table.
DerNalia
as it turns out, and i feel lame for having this issue, I was calling the wrong method. self referential thing can get confusing if variable names don't work right
DerNalia
A: 

tell her she is fat.

FauxReal
Hahahaha, but yeah... -1
Andres Jaan Tack
A: 
    @report = User.find(params[:report])
    @manager = User.find(params[:manager])
    @manager.standard_users.delete(@report)

Managers have standard users standard users have managers

DerNalia