Skip to content

Instantly share code, notes, and snippets.

@crbelaus
Last active June 29, 2019 12:56
Show Gist options
  • Select an option

  • Save crbelaus/82c41b1852021a16e0d9eaa73a0fd3ec to your computer and use it in GitHub Desktop.

Select an option

Save crbelaus/82c41b1852021a16e0d9eaa73a0fd3ec to your computer and use it in GitHub Desktop.
Shows examples of the Trans 2.0 QueryBuilder
# Fetch Articles titled "Trans" in French and having an English comment
# containing the word "good"
iex> Repo.all(from a in Article,
...> join: c in assoc(a, :comments),
...> where: translated(Article, a.title, :fr) == "Trans",
...> where: ilike(translated(Comment, c.comment, :en), "good"))
# SELECT a0."id", a0."title", a0."body", a0."translations"
# FROM "articles" AS a0
# INNER JOIN "comments" AS c1 ON a0."id" = c1."article_id"
# WHERE ((a0."translations"->"fr"->>"title") = "Trans")
# AND ((c1."transcriptions"->"en"->>"comment") ILIKE 'good')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment