This allows consistent search results when using preloads in a custom_index_query, and search_fields.
I ran into issues when trying to search my Profile schema by User.email. Changing to a left join allowed the search filter to work, and provided consistent results.
Schema Modules
defmodule MyApp.Profile do
schema "profiles" do
belongs_to :user, User
field :display_name, :string
...
end
end
defmodule MyApp.User do
schema "users" do
has_one :profile, Profile
field :email, :string
...
end
end
Admin Module
defmodule MyApp.ProfileAdmin
def custom_index_query(_conn, _schema, query) do
from(r in query, preload: [:user])
end
def search_fields(_schema) do
[
:display_name,
user: [:email]
]
end
This allows consistent search results when using preloads in a
custom_index_query
, andsearch_fields
.I ran into issues when trying to search my
Profile
schema byUser.email
. Changing to a left join allowed the search filter to work, and provided consistent results.Schema Modules
Admin Module