-
☆ A M B ☆
- 24,524 Posts
I'm having a bit of trouble setting a default value for a "date" field in an object's map. I would like the default value to be the current date when creating a new item. How would I go about doing that in the schema.xml?
<field key="valid_from" dbtype="date" phptype="date" null="false" default="???"/>
-
☆ A M B ☆
- 24,524 Posts
Reading the MySQL documentation, it turns out that it's not possible (without creating a custom trigger) to use a function such as date() as a default value except for a timestamp, which is not really appropriate in this case.
I'm next turning attention to the ExtJS create new function, so that's probably where I'll need to insert the default date.
Ooops
Too fast reading ^_^ I didn't notice you had set a type 'date' for your field... I generally use timestamps to store dates in the db, it's easy then to return the date (or the part of) in the format I need ...
Cheers
-
☆ A M B ☆
- 24,524 Posts
I'll need a valid_from and a valid_to date, so timestamps aren't appropriate. I'm learning how to configure the ExtJS grids, so that's where I'll initially set up the default value. Then when the new item is saved (or for whatever reason an existing item loses its date), it'll have a value to save.
-
☆ A M B ☆
- 3,141 Posts
<field key="valid_from" dbtype="date" phptype="date" null="false" default="CURRENT_TIMESTAMP" />
I think there's a MySQL limitation allowing only one of those per table (object) though.