Please blame SQLite3, not my feeb capacity to read the Agile book, and
all the blogs.
I want to do many-to-many between two tables. Classic relational stuff, right?
So my schema looks a little bit like this:
create_table "users_props", :force => true do |t|
t.column "prop_id", :integer
t.column "user_id", :integer
That links out to users and props tables, right? So their models
contain the sacred habtm incantations:
class User < ActiveRecord::Base
class Prop < ActiveRecord::Base
All too obvious to post, right? And all straight out of the Daves'
Agile book, right?
Now let's put them in motion:
user.props << prop
That produces a huge error message like this:
I know how to fix that. I replace the syntactic sugar with this old-skool SQL:
insert into users_props(user_id, prop_id)
Okay. The record is probably there (I honestly didn't check.) Now I
try to read it out:
assert_equal 1, quentin.props.count
Now check what _that_ gives:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:
props_users: SELECT count(*) AS count_all FROM props INNER JOIN
props_users ON props.id = props_users.prop_id WHERE
(props_users.user_id = 1 )
Why is it asking for props_users when I have a users_props?