FastSolutions
FastSolutions

Reputation: 1829

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.

Upvotes: 1

Views: 1010

Answers (2)

alvaritono
alvaritono

Reputation: 121

Did you try with with_translated_attribute ?

Upvotes: 0

alvaritono
alvaritono

Reputation: 121

you could try to add to_sql in order to check what sql query is generating

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

Upvotes: 2

Related Questions