I have word's senses and translations in different languages, here is schema http://sqlfiddle.com/#!15/cba5e/2 I need to get all senses and only Spain translations (code "es"), so query should looks like
SELECT *
FROM senses s
LEFT OUTER JOIN translations t ON
s.id = t.sense_id AND t.language_code = 'es';
Can I do it with eager_load/includes/..?
Code like
Sense.includes(:translations).where(translations: { language_code: 'es' })
doesn't work, because it specify conditions in the WHERE clause and generate query like
SELECT *
FROM senses s
LEFT OUTER JOIN translations t ON s.id = t.sense_id
WHERE t.language_code = 'es';
and I get only senses with "es" translations. But I need all senses + spain translations, see the difference: http://sqlfiddle.com/#!15/cba5e/2 and http://sqlfiddle.com/#!15/cba5e/3
From https://www.postgresql.org/docs/current/static/queries-table-expressions.html: Restriction placed in the ON clause is processed before the join, while a restriction placed in the WHERE clause is processed after the join