1

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

以下查询就像一个魅力:

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

当我将查询更改为:

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

它不返回任何值?

存在 where 类为 true 的记录:

=> [#<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-darwin13.4.0]
  • 导轨 3.2.19

编辑1:

我将把它打开一段时间,但据我所知,不可能在 with_translations 查询中添加 where 来查看翻译表。

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

4

2 回答 2

2

您可以尝试添加to_sql以检查生成的 sql 查询

Testimonial.with_translations(I18n.locale).where(:alias => "test").to_sql
于 2015-01-15T12:22:48.823 回答
0

你试过with_translated_attribute吗?

于 2015-01-15T13:00:18.417 回答