Kamva / mgm

Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Apache License 2.0
754 stars 63 forks source link

Added omitempty struct flag to CreatedAt field. #55

Closed CYPH4R closed 2 years ago

CYPH4R commented 3 years ago

Issue: when calling Update() on a collection, null values get written as per JSON/BSON convention, but the update method only handles the UpdatedAt field. As such CreatedAt gets set to 0001-01-01T00:00:00.000+00:00

Fix: set CreatedAt struct flag to omitempty, so that there is no need to extend the Update method.

If this is intended behaviour please let me know and I would love to hear why.

mehran-prs commented 2 years ago

Hi @CYPH4R This is the behavior of the DeafultModel. It assumes that you want to have both CreatedAt and UpdatedAt fields and set the CreatedAt field when creating a new model (by calling the Create method on the collection). Do you want the same behavior in your models?