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

timestamps support in embedded_schema #160

Open
AlexKovalevych opened this issue Jul 25, 2018 · 3 comments
Open

timestamps support in embedded_schema #160

AlexKovalevych opened this issue Jul 25, 2018 · 3 comments

Comments

@AlexKovalevych
Copy link
Contributor

I wasn't able to get timestamps support in embedded_schema. In result timestamp fields are nil for all embedded documents but it works fine for regular documents. Do i miss something, is there a way to get timestamps support for embedded_schema?

@bdtomlin
Copy link

bdtomlin commented Dec 6, 2021

I realize this issue is really old, but it is still an issue which I assume is why it's still open. Since mongoldb_ecto 1.0 is in beta, I assume this is a bug that would need to be fixed before the final release.

When using the timestamps macro from Ecto.Schema in an embedded schema, the inserted_at and updated_at field values are always nil/null.

@scottmessinger
Copy link
Collaborator

@bdtomlin This is a good question! I'm not quite sure how that would be implemented, but my guess is it wouldn't be straightforward conceptually or technically and possibly impossible. Timestamps can be set on the root document whenever it's created/updated, but embedded documents don't have quite as clean of a lifecycle. For instance, I could insert a bunch of comments into a post document and then create the post -- what timestamp do the comments get? Is it the timestamp of when they were added to the post struct or when the post was inserted into the DB? In terms of implementation, my guess is the implementation of timestamps on the root document is straight forward (e.g. add a $set on all the insert* or update*` functions) but how do you implement it on embedded documents that might be embedded deep in a tree?

I'm going to close this for now as I don't see a path forward for this feature. However, if anyone has any ideas on how to implement this, I would welcome the PR and would love to hear ideas on how to make it happen!

@bdtomlin
Copy link

bdtomlin commented Dec 8, 2021

@scottmessinger,

Mongoid handles this with what it calls cascading callbacks. That name gives a pretty decent hint of a way to handle it. https://docs.mongodb.com/mongoid/current/tutorials/mongoid-relations/#cascading-callbacks

I will try to come back to this in the future, but I think it would help to leave it open so it still has visibility for me or anyone else who may need this feature and has some time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants