I am having a collection A which embeds collection B. Collection A as well as collection B includes Mongoid Timestamps (created_at and updated_at).
Now when I create a new entry of collection B (embedded object) using Rails admin, time stamps saved in Database are nil. But if I create a entry from rails console or from a normal api, then timestamps saved in database are not nil.
Any help would be appreciated.
EDIT:
class B
include Mongoid::Document
include Mongoid::Timestamps::Created
include Mongoid::Timestamps::Updated
field :user_id, type: String
field :message, type: String
field :status, type: Integer, default: 1
field :spam_count, type: Integer, default: 0
embedded_in :A
Class B is embedded in class A. When a entry of B is created inside A through rails admin, then created_at and updated_at fields of B are getting saved as nil.
Without class A
or information what mongoid version you use (I'll assume 5.x) I have do some wild guess here that you are missing the cascade_callbacks flag on your embedded relation.
class A
include Mongoid::Document
embeds_many :albums, cascade_callbacks: true
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With