Detecting if a Schema is an embedded_schema

29 views
Skip to first unread message

Giovanni d'Amelio

unread,
Feb 9, 2024, 2:28:13 PMFeb 9
to elixir-ecto
I am playing around with a no/low configuration admin interface to Ecto and one problem I am running into is how to detect if a schema is "normal" or is an embedded one.

Looking through the schema.ex I can't see any good way to tell externally. This is my first time peeking into the Ecto source so I am just wondering if I missed anything obvious?

If I am correct would you all be interested in a contribution to allow it? From my quick read, it seems like I should be able to add a new `__schema__` call (something like `__schema__(:embedded?)`) in here based on the `@ecto_embedded` attribute.

Thanks,
Giovanni d'Amelio

Greg Rychlewski

unread,
Feb 9, 2024, 3:04:56 PMFeb 9
to elixir-ecto
Hi,

Today you are able to tell by the absence of a `__meta__` field in the struct. Since it is documented it is safe to use.

Giovanni d'Amelio

unread,
Feb 9, 2024, 3:31:06 PMFeb 9
to elixir-ecto
Ah! Thanks for the tip. Missed that in the docs.

Thanks,
Gio
Reply all
Reply to author
Forward
0 new messages