-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Hi!
This looks like a cool library. Thank you so much for writing it! I think this is something that is badly needed in Elixirland. I was planning to use it until I (alas!) found a show stopper in my use case scenario.
I have a schema with associations, and I would like to show the main schema fields along with some fields from the associations, and make them searchable and sortable.
For example:
schema "user"do
field(:name, :string)
belongs_to(:organization, Organizaton)
end
schema "organization" do
field(:name, :string)
endIn my Exzeitable table, I'd like to show both the user's name as well as their organization's names. I was able to make it work with this:
use Exzeitable,
repo: DataIngestion.Repo,
routes: Routes,
query:
from(u in User
preload: [:organization]
),
fields: [
name: [label: "User name"],
org_name: [function: true, label: "Organizaiton Name"]
]
def org_name(_socket, entry) do
entry.organization.name
endThis allows me to display the organization's name just fine 👍 However, the field can't neither be sorted or searched because Exzeitable generates the search and sort queries assuming that org_name is a field of the user schema 👎
It seems to me that some support for associations would be in order here. I haven't thought carefully about the details, but maybe it would be enough to implement an association option for fields. Something like:
query: (from u in User),
fields: [
name: [label: "User name"],
org_name: [association: {:organization, :name}, label: "Organizaiton Name"]
]That way, Exzeitable would know that it would have to preload the organization association and use its name field as the value of the org_name field in the table. It might work, but as I said, I haven't thought it through.
Anyway, let me know what you think.