Skip to content

Refactor nil map joins#4602

Merged
greg-rychlewski merged 1 commit intoelixir-ecto:masterfrom
greg-rychlewski:join_nil_map
Apr 8, 2025
Merged

Refactor nil map joins#4602
greg-rychlewski merged 1 commit intoelixir-ecto:masterfrom
greg-rychlewski:join_nil_map

Conversation

@greg-rychlewski
Copy link
Copy Markdown
Member

I think this is cleaner and more general than my last PR. But wanted to get your opinion.

In terms of more general, with this PR we not only handle merges but also the select {map(...from..), map(...join...)} situation we were talking about.

I'm not sure how obvious it is why this works. But basically here:

defp preprocessor({_, {:source, {source, schema}, prefix, types}}, preprocess, adapter) do
    struct = Ecto.Schema.Loader.load_struct(schema, prefix, source)

    fn row ->
      {entry, rest} = struct_load!(types, row, [], false, struct, adapter)
      preprocess(rest, preprocess, entry, adapter)
    end
  end

If we are using map/2 then schema is converted to nil in the planner and then struct is given the value %{}.

@greg-rychlewski greg-rychlewski merged commit ca153d5 into elixir-ecto:master Apr 8, 2025
7 checks passed
@greg-rychlewski greg-rychlewski deleted the join_nil_map branch April 8, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants