lundi 11 janvier 2016

Has_many through not work

My class model looks like below-

Now i am calculating like-

ug =UserGroup.second

ug.destroy

Its give and error like -

*** ActiveRecord::StatementInvalid Exception: Mysql2::Error: Unknown column 'user_groups.' in 'where clause': DELETE FROM user_groups WHERE user_groups.`` = 2

class UserGroup < ActiveRecord::Base
  belongs_to :group
  belongs_to :user
end

class Group < ActiveRecord::Base
  has_many :user_groups, :dependent => :destroy
  has_many :users, :through => :user_groups 
end

class user < ActiveRecord::Base  
   has_many :user_groups  , :dependent => :destroy
   has_many :groups, :through => :user_groups 
end

Where am I Wrong ?

Aucun commentaire:

Enregistrer un commentaire