Forum: Ruby on Rails got SQL error (no id) when updating a join table...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2007-01-05 17:40
I am using a join table 'credentials' w a self-referenced 'users' table
defined as follows:

class User < ActiveRecord::Base
 has_many :credentials_as_referee, :foreign_key => 'referee_id',
:class_name => 'Credential'
  has_many :credentials_as_referenced_user,   :foreign_key =>
'referenced_user_id',   :class_name => 'Credential'
  has_many :referees,  :through => :credentials_as_referenced_user
  has_many :referenced_users,    :through => :credentials_as_referee

class Credential < ActiveRecord::Base
  belongs_to :referee, :foreign_key => "referee_id", :class_name =>
  belongs_to :referenced_user,   :foreign_key => "referenced_user_id",
:class_name => "User"
    # Activates the credential in the database.
   def activate (category)
      update_attributes(   :activation_code => nil, :credential_category
=> category )

creating credential records works fine....
but trying to update a credential record from my controller :
  @credential = Credential.find_by_activation_code(params[:id])

throws an SQL error :

Mysql::Error: Unknown column 'id' in 'where clause':
UPDATE credentials SET  `activation_code` = NULL, `credential_category`
= 2,  WHERE id = NULL

obviously the credentials table doesn't need an id as a join table.....
what's wrong with the update_attributes...  in my model ?

thanks fyl

This topic is locked and can not be replied to.