ruby-on-railsruby-on-rails-3ruby-on-rails-3.2rails-i18nglobalize3

I18n with_translation and where condition


I'm trying to run a query on table Testimonials which has a Translation Table TestimonialTranslations.

The Following query works like a charm:

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

When I change the query to:

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

It doesn't return any values?

A record exists where the where class is 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">]

I know 100% sure that the language is "nl" and that it returns a query when I run:

Testimonial.with_translations(I18n.locale)

These are my specs:

EDIT 1:

I'm going to leave this open for a while but as far as I can see it is not possible to add a where to the with_translations query that will go and look in the translation table.

With this knowledge I will need to do 2 querys.


Solution

  • Did you try with with_translated_attribute ?