2

Looking through my database tables, I'm seeing that the created field is invariably being set as "0000-00-00 00:00:00". The modified field is being auto-populated by sensible dates.

It seems to me very strange that the automagic would get modified right but not created. As far as I can recall I haven't done anything that would unset the created field's value - e.g. specifying it somewhere. Are there any obvious CakePHP "gotchas" I may have fallen foul of that might have messed up my created field in some way?

5
  • Jsut a guess but: you can only have one column with current_timestamp as default value. So if you set created to default to current_timestamp, you only need to auto-populate the modified field. Commented Aug 10, 2011 at 11:43
  • 1
    @cularis not correct, it's not a default value, it's default CakePHP behavior if a field is named "created" to automatically populate that value when save is called. It has to be of type DateTime, which I'm sure it is due to the way it is displaying. there's something else going on here. Commented Aug 10, 2011 at 11:55
  • can you post your model code? Or are you letting CakePHP handle all this? Also, can you post the controller method that is doing the saving of a new item? Also, make sure that there is no hidden fields on the view referencing the created field Commented Aug 10, 2011 at 11:58
  • @stephenbayer - I'm letting CakePHP do all the work I believe. What perplexes me is that this is across many different controllers and models. Some of the records are created from forms in the view, some are sucked in via and API, but it seems like all of them end of without created dates... seems like it must be something pretty fundamental I've done wrong! Commented Aug 10, 2011 at 12:02
  • I'm baffled as well, I'm using the same version of cake in my project, and my created field "just works". I was just thinking that something else is overriding the default behavior. is the DEFAULT value in mysql set to null? if it is not, then cakephp won't touch it according to the documentation Commented Aug 10, 2011 at 12:08

1 Answer 1

2

The only thing I can find in the documentation is that the cakephp only controls this field if it is called "created" and is of type DateTime and the default value is set to NULL. Can you verify that all of this is true in your tables?

Sign up to request clarification or add additional context in comments.

6 Comments

I thought it might be something to do that, as I looked at my tables and the created fields did have "allow null" disabled. However, the same goes for the modified fields, and they are working? I changed one of the tables to have a NULL default for created and added a new record, but the created and modified dates still came out as a bunch of zeroes. (Actually, that probably says something interesting - that modified is only working later, and not at point of initial save?) Bah.
that is interesting. technology is awesome when it works smoothly. Not so much when it doesn't. Do you have an IDE that has debugging like Eclipse with xDebug? Anytime I get really frustrated, I'll step into the code line by line in a debugger until I find where the offensive garbage is happening.
Oh hello, it's working form my development environment, just not live. Something must not be up-to-date there. Now to begin the laborious operation of finding out exactly what!
good luck, man. I know it gets frustrating when something that is supposed to work isn't actually working. I'm having a few of those types of issues myself on the project I'm working on this morning.
+1. This is the correct answer according to this post: sanisoft.com/blog/2007/06/15/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.