2013-05-08 72 views
0

爲什麼這項工作很好:的ActiveRecord :: StatementInvalid未知列錯誤

Tag.create(game_id: 1, tagged: u) 

但這:

tags = Tag.where(game_id: 1, tagged: u).includes(:tagged) 

給出了錯誤:

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'tags.tagged' in 'where clause': SELECT `tags`.* FROM `tags` WHERE `tags`.`game_id` = 1 AND `tags`.`tagged` = 1 

BTW,uActiveRecord::Base sublcass。

Tag表結構:

create_table :tags, force: true do |t| 
    t.references :game 
    t.references :tagged_by 
    t.references :tagged 
    t.timestamps 
end 
+0

是列'tagged'駐留在你的'tag'表 – 2013-05-08 19:28:21

+0

您可以發佈您'Tag'模式? – pungoyal 2013-05-08 19:30:49

+0

也顯示錶結構 – 2013-05-08 19:31:30

回答

2

嘗試做

tags = Tag.includes(:tagged).where(game_id: 1, tagged_id: u.id) 
相關問題