为什么这可以正常工作:
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
顺便说一句,u
是ActiveRecord::Base
子类。
Tag
表结构:
create_table :tags, force: true do |t|
t.references :game
t.references :tagged_by
t.references :tagged
t.timestamps
end