two tables, users and languages,
one user may have many languages, one language may belong to many users.
so, I create the joint table users_languages with user_id and
language_id only.
class User < ActiveRecord::Base
has_and_belongs_to_many :languages
end
class Language < ActiveRecord::Base
has_and_belongs_to_many :users
end
class UsersLanguages < ActiveRecord::Base
belongs_to :users
belongs_to :languages
end
I also create one sample user data into users tables and one sample
language data into languages table. nothing in joint table
users_languages.
then, I go to console to test:
if I use the following code, everything is fine.
l=Language.new
u=User.new
u.languages << l
but when I use the real data, still under console,
l=Language.find(1)
u=User.find(1)
u.languages << l
when I am at the third line, I will get an error message like this:
ActiveRecord::StatementInvalid: PGError: ERROR: relation
“languages_users” does not exist
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = ‘languages_users’::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
any reason for that? thanks for any help.