maz

maz

Flop: join_fields across table and association does not appear in result

Using Flop I want to return a list of tuples containing a Membership along with associated User.email

membership.ex:

  @derive {
    Flop.Schema,
    filterable: [:member_email],
    sortable: [:member_email],
    join_fields: [member_email: [binding: :joined_user, field: :email]]
  }

  @role_options ~w(admin member)a

  schema "orgs_memberships" do
    field :role, Ecto.Enum, values: @role_options
    field :is_inactive, :boolean, default: false
    ...
    belongs_to :user, User
    belongs_to :org, Org


  def all_by_org_joined(%Org{} = org) do
    joined = from(m in __MODULE__,
      join: u in assoc(m, :user),
      as: :joined_user,
      join: o in assoc(m, :org),
      on: o.id == ^org.id
    )

    dbg(joined)

    result = joined
    |> Markably.Repo.all()

    dbg(result)

result prints as but seems to be missing member_email:

result #=> [
  %Markably.Orgs.Membership{
    __meta__: #Ecto.Schema.Metadata<:loaded, "orgs_memberships">,
    id: "1eda8b14-bf24-6736-85c7-a1d5647b6bd8",
    role: :admin,
    is_inactive: false,
    user_id: "1eda8b14-be9c-6822-8ab9-61e2ff5b420b",
    user: #Ecto.Association.NotLoaded<association :user is not loaded>,
    org_id: "1eda8b14-bf22-6d6e-b325-ea3ac7994ddf",
    org: #Ecto.Association.NotLoaded<association :org is not loaded>,
    inserted_at: ~N[2023-02-09 19:38:15],
    updated_at: ~N[2023-02-09 19:38:15]
  },
  %Markably.Orgs.Membership{
...

Am I doing this right?

flop 0.19.0
ecto 3.9.4
elixir 1.14.2

regards, Michael

First Post!

woylie

woylie

You’re missing a select. Flop only adds where and order by clauses, it won’t add a select for you.

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement