updatedAt NOT updating

148 views
Skip to first unread message

Chris Geirman

unread,
Jul 23, 2019, 4:13:47 PM7/23/19
to CFWheels
I've noticed that the updatedAt timestamps of my models is not automatically being updated even though I'm using the ORM to make the updates. I have to believe this is a problem for me only, but I'm not sure where to begin troubleshooting. Maybe I have a config flag thrown somehow I'm not aware of?

Pointers appreciated...
CFML Engine: Lucee 5.3.2.77

Tom King

unread,
Jul 24, 2019, 6:35:16 AM7/24/19
to CFWheels
I'd start with checking the model is properly running the update hooks.
You could add an `afterUpdate` filter to `models/Model.cfc` (https://api.cfwheels.org/v2.0/model.afterUpdate.html )
To call a method to log the changes - you can see an example here: https://github.com/cfwheels/cfwheels-example-app/blob/master/models/Model.cfc where I'm logging the changed values of a model.

It could be for instance that your update is silently failing in some way which you've not caught properly.

If the updated values are being correctly saved, but the updatedAt flag genuinely isn't being updated, then I'd check that the TimeStampOnUpdateProperty is correctly listed as updatedAt, and that SetUpdatedAtOnCreate is set to true (which are the defaults).
Lastly, I'd double check the column type of the updatedAt field, which for me in mySQL would be DATETIME, with NULL as default and On Update Current_Timestamp unticked.

I guess the last consideration would be timezones, as 2.x uses UTC by default (set the global timeStampMode setting to local to reinstate the old behaviour) - whether that's causing an issue or not.

That's all I can think of for now :)

T

Chris Geirman

unread,
Jul 27, 2019, 11:31:36 PM7/27/19
to CFWheels
Hey Tom,

Thanks for your reply. I just went through all your suggestions. The problem is occurring within every model, where I'm using the migration tool's `t.timestamps()` to generate the timestamp columns. Here's an example of just the user model. I'm providing it because I'm not really sure what you meant when you said "and On Update Current_Timestamp is unticked"

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(24) NOT NULL,
  `lastname` varchar(24) DEFAULT NULL,
  `mobile` varchar(48) DEFAULT NULL,
  `password` varchar(64) NOT NULL,
  `email` varchar(256) NOT NULL,
  `resettoken` varchar(48) DEFAULT NULL,
  `lastseen` datetime DEFAULT NULL,
  `resettokenexpirery` datetime DEFAULT NULL,
  `waiverat` datetime DEFAULT NULL,
  `forcenewpassword` tinyint(1) DEFAULT '0',
  `isverifiedemail` tinyint(1) DEFAULT '0',
  `isadmin` tinyint(1) DEFAULT '0',
  `iscoordinater` tinyint(1) DEFAULT '0',
  `createdat` datetime DEFAULT NULL,
  `updatedat` datetime DEFAULT NULL,
  `deletedat` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=70 DEFAULT CHARSET=utf8;


I have followed your example app to track changes in the auditlog model. When I update the user model, I'll see an entry like this...
{"model":"User","properties":{"firstname":{"CHANGEDTO":"Chris","CHANGEDFROM":"Chri"}},"key":"1"}

As you can see, updatedAt is not one of the changes tracked, but the other changes (firstname in this example) do successfully save to the database.

I also tried adding set(timeStampMode="local"); to the settings file, but got no love from that either. I have Lucee setup to use UTC as the server time also, so I would expect that to be compatible with the 2.x default.

I appreciate all your thoughts. So far, nothing seems to have helped me understand this. I'll start digging into the wheels code and see if I can get any closer to figuring out what the problem might be. If you can think of any particular files I should start looking at, I'd appreciate it.

Chris Geirman

unread,
Jul 28, 2019, 1:02:33 AM7/28/19
to CFWheels
FYI—as a stop gap, I've added this.updatedAt = now(); to the beforeSave() hook in the Model, and that seems to be working. Still not sure why the framework isn't working as expected.

Tom King

unread,
Jul 28, 2019, 5:12:57 AM7/28/19
to cfwh...@googlegroups.com
Can you try the current master? Fair few changes to that code already in there..
T

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cfwheels/a46873bf-87d7-4235-88a5-a7faaa7effb6%40googlegroups.com.
--


Tom King

Web Development Consultant

+44(0)7775 926480 | oxalto.co.uk | @neokoenig | linkedIn

Chris Geirman

unread,
Jul 30, 2019, 6:45:18 PM7/30/19
to CFWheels
Well, strangely enough this solved the problem. I must have already been using master because the only diff between what I was using and the "wheels" directory I copied over from master is this...

application.$wheels.setUpdatedAtOnCreate = true;

it was previously set to false. Somehow though, this resolved the problem. I would have thought this should only affect the created object though, not the updated object. Therefore, I don't understand why it resolved the problem...but it has.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwh...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages