Noob AR many_to_many problem

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!!


Support the World Aids Awareness campaign this month with Yahoo! for
Good

Solved. Removed ubuntu’s rails and installed 2.0.2 using gems.
Everything works as it should.

Anthony G. [email protected] wrote: 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!!


Support the World Aids Awareness campaign this month with Yahoo! for
Good

Disclaimer: Technically, I’m always wrong!!


Sent from Yahoo! - a smarter inbox.

On 19 Jan 2008, at 18:25, Anthony G. wrote:

Solved. Removed ubuntu’s rails and installed 2.0.2 using gems.
Everything works as it should.

That may be the case, but this will probably popup later on: with
has_many :through, UserJob is a genuine model so should have a
primary_key.

Fred

Noted, thx. I’m only playing around and have now gone back to habtm.
Also went to rails 1.2.6.

Frederick C. [email protected] wrote:

On 19 Jan 2008, at 18:25, Anthony G. wrote:

Solved. Removed ubuntu’s rails and installed 2.0.2 using gems.
Everything works as it should.

That may be the case, but this will probably popup later on: with
has_many :through, UserJob is a genuine model so should have a
primary_key.

Fred

u = User.find(1)
0xb709e7d4 …>, @errors={}>>], @attributes={“name”=>“Anthony”,
end

CREATE TABLE users (

Disclaimer: Technically, I’m always wrong!!
Support the World Aids Awareness campaign this month with Yahoo! for
Good
Sent from Yahoo! - a smarter inbox

Disclaimer: Technically, I’m always wrong!!


Support the World Aids Awareness campaign this month with Yahoo! for
Good