我试图在表格Testimonials上运行查询,该表格具有翻译表TestimonialTranslations。
以下查询就像魅力一样:
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">]
我完全知道该语言是&#34; nl&#34;并且它在我运行时返回一个查询:
Testimonial.with_translations(I18n.locale)
这些是我的规格:
编辑1:
我打算暂时保持这种状态,但据我所知,无法在转换表中查看将要查看的with_translations查询的位置。
有了这些知识,我需要做2个查询。
答案 0 :(得分:1)
您可以尝试添加to_sql
以检查正在生成的SQL查询
Testimonial.with_translations(I18n.locale).where(:alias => "test").to_sql
答案 1 :(得分:0)
你试过with_translated_attribute
了吗?