Skip to content

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

@rhcarvalho

Description

@rhcarvalho

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions