I18n with_translation and where condition



我正在尝试对具有翻译表推荐翻译的表推荐运行查询。

以下查询的工作方式类似于超级按钮:

Testimonial.with_translations(I18n.locale).where(:id => params[:id]).first

当我将查询更改为:

Testimonial.with_translations(I18n.locale).where(:alias => "test").first

它不返回任何值?

存在一个记录,其中 where 类为真:

=> [#<Testimonial id: 1, title: "Test", person: "", image_uid: nil, content: "<p>zfzefzfLorem ipsum dolor sit amet, consectetur a...", interest_group: "", created_at: "2015-01-15 11:48:11", updated_at: "2015-01-15 11:48:11", job: "", overview: true, content_short: "<p>Lorem ipsum dolor sit amet, consectetur adipisci...", hidden: false, hide_image: false, alias: "test">]

我知道 100% 确定该语言是"nl",并且在我运行时它会返回一个查询:

Testimonial.with_translations(I18n.locale)

这些是我的规格:

  • Ruby 1.9.3P550 (2014-10-27 修订版 48165) [x86_64-达尔文13.4.0]
  • 导轨 3.2.19

编辑 1:

我将暂时保持开放状态,但据我所知,无法在with_translations查询中添加 where 并查看转换表。

有了这些知识,我需要做 2 个查询。

您可以尝试添加to_sql以检查SQL查询正在生成的内容

Testimonial.with_translations(I18n.locale).where(:alias => "test").to_sql

你试过with_translated_attribute吗?

最新更新