I’m receiving the following error …
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: id: UPDATE user_jobs SET user_id = NULL WHERE (user_id = 1 AND id IN (NULL))
while trying to delete from a join table. Here’s the sequence from the console …
u = User.find(1) => #<User:0xb70bc810 @attributes={“name”=>“Anthony”, “id”=>“1”}> j= Job.find(4) => #<Job:0xb70aa8f4 @attributes={“title”=>“Farmer”, “id”=>“4”}> u.jobs << j => [#<Job:0xb70aa8f4 @attributes={“title”=>“Farmer”, “id”=>“4”}>] u => #<User:0xb70bc810 @user_jobs=[#<UserJob:0xb7098ec4 @attributes={“job_id”=>“4”, “user_id”=>“1”}>, #<UserJob:0xb709e7d4 @new_record=false, @attributes={“job_id”=>4, “id”=>1, “user_id”=>1}, @errors=#<ActiveRecord::Errors:0xb709c560 @base=#<UserJob:0xb709e7d4 …>, @errors={}>>], @attributes={“name”=>“Anthony”, “id”=>“1”}, @jobs=[#<Job:0xb70aa8f4 @attributes={“title”=>“Farmer”, “id”=>“4”}>]> dj = u.jobs.find(4) => #<Job:0xb7095c60 @attributes={“title”=>“Farmer”, “id”=>“4”}> u.jobs.delete(dj)
Here are my classes class Job < ActiveRecord::Base has_many :user_jobs has_many :users, :through => :user_jobs end
class User < ActiveRecord::Base has_many :user_jobs has_many :jobs, :through => :user_jobs end
class UserJob < ActiveRecord::Base belongs_to :job belongs_to :user end
Here is my schema CREATE TABLE jobs ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL ); CREATE TABLE user_jobs ( user_id INTEGER NOT NULL, job_id INTEGER NOT NULL, PRIMARY KEY(user_id,job_id) ); CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL );
rails 1.2.4 fron ubuntu.
Any pointers would be great.
thx -ants
Disclaimer: Technically, I’m always wrong!!