0

为什么这可以正常工作:

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

顺便说一句,uActiveRecord::Base子类。

Tag表结构:

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

1 回答 1

2

尝试做

tags = Tag.includes(:tagged).where(game_id: 1, tagged_id: u.id)
于 2013-05-08T19:28:51.800 回答