Ruby on rails ActiveRecord::语句无效未知列错误
为什么这样做很好:Ruby on rails ActiveRecord::语句无效未知列错误,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,为什么这样做很好: 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
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
subcass
标记
表格结构:
create_table :tags, force: true do |t|
t.references :game
t.references :tagged_by
t.references :tagged
t.timestamps
end
试着做
tags = Tag.includes(:tagged).where(game_id: 1, tagged_id: u.id)
列
taged
是否驻留在您的tag
表格中您可以发布您的tag
模型吗?同时显示表格结构