fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
152 stars 96 forks source link

Adds the ability to include relations when using the UpdatedAt observer #315

Closed emlynwest closed 11 years ago

emlynwest commented 11 years ago

Putting this up here to get thoughts on the feature/implementation. I thought this would be a useful feature as often an ORM entity consists of multiple models.

My example is that a blog post has many "i18ns", translatable data stored in a separate table (so another model), when any of the i18ns are updated I want to be able to reflect that change on the parent blog post. This observer will allow this to work.

$blog_post->i18ns[$i18n_id]->title = 'My new title';
$blog_post->save();
// $blog_post->updated_at is now "now()"

The added setting is used like this:

protected static $_observers = array(
    'Orm\\Observer_UpdatedAt' => array(
        'events' => array('before_save'),
        'mysql_timestamp' => true,
        'property' => 'updated',
        'relations' => array(
                'i18ns',
        ),
    ),
);

Docs are on the way.

WanWizard commented 11 years ago

docs ? ;)

emlynwest commented 11 years ago

As usual something exploded and needed to be fixed. I'll try and get the PR for the docs up today.

emlynwest commented 11 years ago

fuel/docs#599 for docs.

emlynwest commented 11 years ago

Just need to fix an issue of not being able to handle has_one or belong_to