Hey all,
I have three tables:
groups(id,name)
forums(id,name)
permissions(group_id,forum_id,read_forum,post_replies,post_topics)
# now in script/console I do:
forum=Forum.find_first
group=Group.find_first
perm=Permission.create(:read_forum=>0,:post_replies=>0,:post_topics=>0)
# then when I do:
group.permissions << perm
I get:
ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column
'id' in 'where clause': UPDATE permissions SET `read_forum` = 0,
`group_id` = 5, `post_replies` = 0, `forum_id` = 5, `post_topics` = 0
WHERE id = 0
any idea what's wrong?
thanx in advance
Pat
Hello Patrick,
I have three tables:
groups(id,name)
forums(id,name)
permissions(group_id,forum_id,read_forum,post_replies,post_topics)
If you've got Group has_many :forums, :through => :permissions
and Forum has_many :groups, :through => :permissions
then your permissions table must have an id column.
Your migration should look like this :
create_table :permissions do |t|
t.column :group_id, :integer
t.column :forum_id, :integer
t.column :read_forum, :integer # with some :default => 0 maybe
t.column :post_replies, :integer
t.column :post_topics, :integer
end
# now in script/console I do:
forum=Forum.find_first
group=Group.find_first
find :first is less deprecated thant find_first
-- Jean-François.