Skip to content

Refactor nil map joins #4602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

greg-rychlewski
Copy link
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