我试图在我的数据库中查询与当前查看的记录(基于标记)相似的记录,我正在工作,但我想随机化顺序。
我的开发环境是mysql所以我会做类似的事情:
@tattoos = Tattoo.tagged_with(tags, :any => true).order("RAND()").limit(6)
哪个有效,但是我的生产环境是使用 postgresql 的 heroku,所以我尝试使用它:
@tattoos = Tattoo.tagged_with(tags, :any => true).order("RANDOM()").limit(6)
但我收到以下错误:
ActionView::Template::Error (PGError: ERROR: for SELECT DISTINCT, ORDER BY 表达式必须出现在选择列表中
SELECT DISTINCT tattoos.* FROM "tattoos" JOIN taggings
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477 ON
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.taggable_id = tattoos.id AND
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.taggable_type = 'Tattoo' WHERE
(tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.tag_id = 3 OR
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.tag_id = 4 OR
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.tag_id = 5 OR
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.tag_id = 24 OR
tattoos_taggings_color_fantasy_newschool_nerdy_tv_477.tag_id = 205) ORDER BY RANDOM() LIMIT 6):