Skip to content

Returning a translated record from the DB #78

@bigardone

Description

@bigardone

👋🏼 Hi there, I just started using this great library (thanks for sharing it 🙌🏼 ), and I was wondering what would be the best approach to return a translated record from the DB. From what I've read in the main version, translated_as returns a translated field that Ecto can load into a struct, so I'm doing something like the following:

  def with_translated_name(query, locale) do
    from c in query,
      select_merge: %{name: translated_as(Car, c.name, locale)}
  end

Is this how it is intended to be used, or is there a better way of doing it without the select_merge?
I haven't found any examples in the tests.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions