Skip to content
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

Mongo.Collection.embeds_one/3 doesn't save type information #242

Open
rhcarvalho opened this issue May 3, 2024 · 1 comment
Open

Mongo.Collection.embeds_one/3 doesn't save type information #242

rhcarvalho opened this issue May 3, 2024 · 1 comment

Comments

@rhcarvalho
Copy link
Contributor

Hi @zookzook, thanks one more time for maintaining this library and merging my contributions!

I'm not sure yet what's the use for the types when defining a module with use Mongo.Collection. Is it just for documentation/humans?

There doesn't seem to be any form of validation, nor does it seem to influence the default encoding/decoding process (and I'm okay with that).


Nonetheless, I noticed that calling SomeCollection.__collection__(:types) includes some info about a document attribute set with embeds_many, but missed a similar attribute set with embeds_one.

@doc """
Adds the struct to the `embeds_one` list.
"""
def __embeds_one__(mod, name, target, opts) do
Module.put_attribute(mod, :embed_ones, {name, target, add_name(mod, opts, name)})
end

@doc """
Adds the struct to the `embeds_many` list.
"""
def __embeds_many__(mod, name, target, type, opts) do
Module.put_attribute(mod, :types, {name, type})
Module.put_attribute(mod, :embed_manys, {name, target, add_name(mod, opts, name)})
end

In embeds_many the type is derived as type = unquote(Macro.escape({{:., [], [mod, :t]}, [], []})). I'm not sure what would be expected for the embeds_one case, any advice?

@zookzook
Copy link
Owner

zookzook commented May 6, 2024

The type spec is just for documentation. I need some time to look at it and to remember how it works.

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

No branches or pull requests

2 participants