Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm
Orm\Observer_UpdatedAt before_update? before_save?
yossy
October 2013
Hi, I would like to ask one about Orm\Observer_UpdateAt on models.
I got the following model code.
>>
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => true,
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_update'),
'mysql_timestamp' => true,
),
);
<<
With the above, when I update the model, the db column "updated_at" is not updated.
If I try "before_save" instead, it works.
According to
http://fuelphp.com/docs/packages/orm/observers/included.html#os_updated
, both should work.
What is the cause?
FYI, I post the updated part of controller (extends Controller_Rest).
>>
public function put_data()
{
$props = Input::put();
$model = Model_M_Company::find($props['id']);
$model->set(array(
'name' => $props['name'],
'tel' => $props['tel'],
'address' => $props['address'],
'remarks' => $props['remarks'],
'company_status_id' => $props['company_status_id'],
));
$model->save();
$this->response($model);
}
<<
Thank you in advance.
Harro
October 2013
Accepted Answer
Which version of Fuel are you using?
"before_update" support was added in 1.6.1.
yossy
October 2013
Wow, I didn't know it. My version is 1.6.. Thanks!
>>
$ oil -v
Fuel: 1.6 running in "development" mode
<<
Harro
October 2013
You can just copy the observer file from the 1.6.1. repo to make it work.
1.7 will be released one of these days, you can also wait and upgrade to that.
yossy
October 2013
Thank you for the advice. I did what you told:
- Copying 1.6.1 version of fuel/packages/orm/classes/observer/updatedat.php
That worked!! Thanks again.
Harro
October 2013
You're welcome. Happy coding!
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
October 2013
yossy
October 2013