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

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.
Kad K. (Guest)
on 2007-01-05 18: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 =>
"User"
  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 )
  end
....


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

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


kad
This topic is locked and can not be replied to.