Closed paulchubatyy closed 14 years ago
Emmm... so... what's the problem? :)
The fields are acting vice versa. If "auto_now_create" is set to true the field doesn't get the current time as default value
Ok, maybe because Jelly uses UNIX timestamps (INT), not date, datetime, or other such string-type fields.
"timestamp" is saved as int in the database as far as I know.
"timestamp" is saved as int in the database as far as I know.
Timestamp is stored as a mysql timestamp (which is int based but is not treated just like an int by the query).
Jelly timestamp fields are designed to be used with straight Integer fields where the actual value in the queries is specified as a timestamp throughout. There are many points of view about whether this is a good solution or not and it will vary based on your situation. That is the convention though and is how Jelly is designed.
If you want to use mysql date or timestamp fields, you will need to write your own field classes that input and output the data as mysql expects.
I'll close this as the wrong data type is almost certainly the problem here.
Jelly timestamp fields are designed to be used with straight Integer fields where the actual value in the queries is specified as a timestamp throughout
This isn't entirely true. When interacting with the model, timestamp data always comes back as UNIX timestamps (integers), however they can be configured so that before saving they are converted into a format the database recognizes.
The fields should be set up as this:
'foo' => new Field_Timestamp(array(
'auto_now_update' => TRUE,
'format' => 'Y-m-d H:i:s'
));
'format' specifies the string passed to PHP's date function to format the time.
Thanks Jonathan, I've got your point and the field is working as intended with format string.
I have the following four fields in my model. The declaration is pretty straightforward.
But when creating (saving for the first time) the model all the fields are stored with the current time except of created_at.
Here is the sql I used for the field declaration:
cheers!