zookzook / elixir-mongodb-driver

MongoDB driver for Elixir
Apache License 2.0
245 stars 63 forks source link

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

Open rhcarvalho opened 6 months ago

rhcarvalho commented 6 months ago

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.

https://github.com/zookzook/elixir-mongodb-driver/blob/6071f18eeabffab634db509f85a734ddcf9eb2a6/lib/mongo/collection.ex#L888-L894

https://github.com/zookzook/elixir-mongodb-driver/blob/6071f18eeabffab634db509f85a734ddcf9eb2a6/lib/mongo/collection.ex#L905-L911

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 commented 6 months ago

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