mysql - Delete only join record between tables in Rails 4 -


i have 3 rails models as:

class user < activerecord::base   has_and_belongs_to_many :char_factors end  class charfactor < activerecord::base   has_and_belongs_to_many :users end  class usercharfact < activerecord::base   belongs_to :user   belongs_to :char_factor end 

in above user , charfactor models joined through usercharfact model.

i'm creating new relations as:

def create   @user_character = usercharfact.create({:user_id => @user.id, :char_factor_id => factor_id.id}) end 

and above seems working properly. can't find way delete specific join relation between 2 tables. tried following:

def destroy   @user_character = charfactor.find(params[:id])   @user.char_factors.delete(@user_character) end 

but deletes value charfactor table rather deleting association

usercharfact.where(char_factor_id: params[:id], user_id: @user.id).destroy_all


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -