質問

I've got an application built in Laravel 3 and I've run into a very strange bug. I have a model with two datetime fields: start_time and end_time. I also have the timestamps enabled for this model so there are also created_at and updated_at datetime fields.

I have a controller action which handles the editing/updating of objects within this model. When running this action, every other time you change the end_time field, the start_time field is overwritten with the minutes and seconds of the updated_at field. I know this sounds crazy but here are some things I've done while debugging.

First I switched from using the fill_raw($input) function and started using manual assignment in case there was something weird going on there.

    $object->start_time = $start_time;
    $object->end_time = $end_time;
    $object->save();

I've also added echo statements all throughout the action to make sure the value wasn't being changed at any point, including one that prints the value stored in the object after the save() function is called. Every time the value is as expected. However, sometime between the end of the action where the page is redirected and when the page reloads, the value is being changed in the database.

At this point I'm thinking it must be something weird on the database end since I know that for instance in PHPMyAdmin when you're manually adding a row it will auto-fill datetime fields with NOW when they're set to NOT NULL but not filled in. But that being said, I've already double-checked that the field isn't empty as has the correct value. I'm at a dead-end here and could really use another perspective.

EDIT:
Here's a link to a copy of the controller action in question. Again I'll point out that there are echo statements throughout the action which I have used to verify that the input data is correct and not being altered in any unexpected ways throughout the entire action. The problem I'm encountering only appears after the action has run.

役に立ちましたか?

解決

A column that updates to the current time is consistent with it having an ON UPDATE CURRENT_TIMESTAMP clause.

Issuing a SHOW CREATE TABLE yourtablename can confirm it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top