-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Why MongoDate is converted to string ? #64
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
Comments
If you want to work with "custom" date fields, you need to specify them in your model like you would with the original Eloquent model. https://github.com/jenssegers/Laravel-MongoDB#dates |
Thank's for your fast answer. I have missed a part of the story ! The following line solve my issue : protected $dates = array('date_start'); So, it's not very important to me now, but why convert MongoDate to string ? It could be the role of a custom getter, to let everyone choose its own output format. (I let you close the issue if it's ok for you). |
The reason I convert it to a string is mainly for the JSON output of the model. But it should not really matter if you specify the date fields in the model class. |
Why does the documentation say "Internally, these dates will be converted to MongoDate objects when saved to the database."? |
@robcaw, only if you specify them in your class: |
Oh right. I have On Mon, Nov 25, 2013 at 7:22 PM, Jens Segers [email protected]:
|
That should not happen. This functionality is tested in https://github.com/jenssegers/Laravel-MongoDB/blob/master/tests/ModelTest.php#L312 |
Nevermind, I hadn't saved the date string as a DateTime object when creating my User. Thanks! |
The default behavior is to convert MongoDate to string after the requests.
Why ? If we save a date as a MongoDate, it is to be able to make operation on this field. For example, detect the number of days since a start date.
Today, we have very strange cases like this one :
And a default string format is not very useful because it is different for each country (I'm french...). Something more useful could be to override the MongoDate
__toString
method but I'm not sure that it is the role of this package.The text was updated successfully, but these errors were encountered: