Comments (2)
You're right as in the update process, the timestamps attributes are set with Carbon::now() which the Illuminate Query translate into the correct datetime format, but the inverse is not true, as date attribute is hydrated as a string, which leads to this inconsistency.
Several ways to solve this :
- Cast the carbon object to string after the update/create query.
- Hydrate date attributes with instance of Carbon.
- Add a $dates attribute to the entity map to customize this behaviour. If the attribute is contained in the array, it will be hydrated with an instance of Carbon, if it's not with a string. Of course this raises the question of which behaviour to choose as a default for the timestamps. I'd tend to go on the Carbon side, but i'd like to make some benchmarks to see if it's not too costy in terms of hydration performance.
That's for the big picture.
Concerning the toArray() method, I think we can simply test if the attribute is an instance of carbon, and casting it to string if it's so. This will work whatever option we choose for the hydration behaviour. Feel free to PR it ;)
from analogue.
Fixed the casting in v2.1.7 release
from analogue.
Related Issues (20)
- What is the best way to 'detach' a relation? (in my case, belongsToMany) HOT 2
- What's the best way to count a relation without loading the Entities? HOT 7
- Translations base on analogue Orm HOT 3
- Unable to save foreign keys in 5.5 HOT 3
- Undefined variable: factory HOT 1
- The update $dirtyRelatedAggregates override foreighn keys to null HOT 7
- Documentation Request HOT 3
- The problem with storing entity with embedding object HOT 3
- CollectionProxy does not implement some Collection methods correctly HOT 2
- 5.5 entities with generated proxies are unable to serialize due to a closure HOT 2
- (Feature Request) Composite Keys HOT 1
- Problem hydrating relations HOT 3
- Is it possible to have properties of entity in camelCase, but fields in DB are in snake_case? HOT 3
- SoftDeletes not working HOT 2
- Automatically eager load not working HOT 1
- Incomplete BelongsToMany eager loads HOT 5
- Eloquent 5.7 HOT 3
- Analogue Slim Framework/Silex HOT 3
- Can we map columns to class properties? HOT 4
- Can't install Analogue on Laravel 6 HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from analogue.