Skip to content

Support querying on multiple locales at once#232

Merged
shioyama merged 3 commits intomasterfrom
table_alias_locale
May 26, 2018
Merged

Support querying on multiple locales at once#232
shioyama merged 3 commits intomasterfrom
table_alias_locale

Conversation

@shioyama
Copy link
Copy Markdown
Owner

@shioyama shioyama commented May 26, 2018

This is currently supported (although not tested) by all backends except KeyValue and Table. Should be straightforward to support universally.

The format looks like this:

Post.i18n(locale: :en) do |en|
  Post.i18n(locale: :ja) do |ja|
    en.title.eq("Title").and(ja.title.eq("タイトル"))
  end
end

This queries for a post with an English title Title and a Japanese title タイトル, but obviously you could build much more complex logic.

Here is the resulting SQL for a Jsonb backend:

SELECT "posts".* FROM "posts"
WHERE ("posts"."title" -> 'en') = '"foo"' AND ("posts"."title" -> 'ja') = '"bar"'

The problem with KeyValue and Table backends is that their respective joins do not alias the table name with an alias that includes the locale.

@shioyama shioyama force-pushed the table_alias_locale branch from 8fe9ede to 1fc9ce0 Compare May 26, 2018 05:11
@shioyama shioyama changed the title [WIP] Support querying on multiple locales at once Support querying on multiple locales at once May 26, 2018
@shioyama shioyama force-pushed the table_alias_locale branch 3 times, most recently from 6a9c49e to ecce62d Compare May 26, 2018 12:50
@shioyama shioyama force-pushed the table_alias_locale branch from 6be862f to c0c04e3 Compare May 26, 2018 13:54
@shioyama shioyama merged commit c0c04e3 into master May 26, 2018
@shioyama shioyama deleted the table_alias_locale branch May 27, 2018 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant