spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Date/Datetime fild.types error #267

Closed mateomu18 closed 6 years ago

mateomu18 commented 6 years ago

When i create an entity with a date/datetime attribute and set de "default" property of this fieldtype like new \Date() or new \DateTime() or new \Date(string) the migration done after returned an error. Why is this happening?? Error:

Recoverable fatal error: Object of class DateTime could not be converted to string in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php on line 2341

My intention is to do something like that:

CREATE TABLE table1 (
  date1 datetime NULL DEFAULT now()
);

MySql version: 10.2.12-MariaDB Php version: 7.2.1

Thanks in advance.

vlucas commented 6 years ago

The "default" property is for the SQL/db default. Use value instead: 'date_created' => ['type' => 'datetime', 'value' => new \DateTime()],

mateomu18 commented 6 years ago

Thak you!

2018-06-09 13:34 GMT-03:00 Vance Lucas notifications@github.com:

The "default" property is for the SQL/db default. Use value instead: 'date_created' => ['type' => 'datetime', 'value' => new \DateTime()],

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spotorm/spot2/issues/267#issuecomment-395982378, or mute the thread https://github.com/notifications/unsubscribe-auth/AdgVepmdlU1V4dbJD1Ny0TxIwkaMkhpiks5t6_kZgaJpZM4Ugjfg .