⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@jswanner
Copy link

@jswanner jswanner commented Mar 1, 2025

@josevalim
Copy link
Member

It looks good to me, although I am a bit worried about loading virtual fields. Do you have thoughts @greg-rychlewski? Worst case scenario we require it to be opt-in via a flag.

@greg-rychlewski
Copy link
Member

I think it would have to be opt-in because the function is shared by embedded loading. So if it wasn't opt-in virtual embed fields would start appearing in results.

Using the schema as the type definition feels a bit off to me if wanting to load virtual fields. They are ignored in all the other Schema API functions, as far as I can see.

Maybe it would make sense to expand the reflection api so the user can create their own type map?

@greg-rychlewski
Copy link
Member

I looked into this again given there was a second request. The two main takeaways I see:

  1. It has to be optional because loading embeds from queries shares the same code path. So if it's always true it will change the return value of queries that contain embeds with virtual fields.
  2. The biggest "gotcha" for making it optional is when you are calling load on a schema that has an embed that has a virtual field. Because it eventually calls adapter_load which calls the loaders function in the adapter like this https://github.com/elixir-ecto/ecto_sql/blob/383561d3bfab7bedbbf2080538c4043ef4c783a4/lib/ecto/adapters/tds.ex#L148. So that whole flow would need to be changed to conditionally apply virtual fields.

So I believe it's doable but probably a bigger change than anticipated. I think at minimum you have to add an optional 3rd field to the loaders callback in the adapter to conditionally apply virtuals.

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.

3 participants