fuel / orm

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

Model_Temporal + Observer_Self with "after_insert" #357

Closed thiver closed 9 years ago

thiver commented 10 years ago

When I place an Observer_Self on a Temporal Model with the event "after_insert", the event gets called every time a change has been made to an object. So on every new row in the database table, there is an after_insert call. Shouldn't this be limited to the first temporal row of the object only?

I solved the problem with the following hack for now:

    protected static $_observers = array('Orm\\Observer_Self' => array('events' => array('after_insert')));

    public function _event_after_insert(){
        $count = DB::select(DB::expr('COUNT(*) as count'))->where('id',$this->id)->from(static::$_table_name)->execute();
        $count = $count->current();
        $count = $count['count'];
        if($count == 1):
        // real event code here
        endif;
    }
emlynwest commented 10 years ago

It should and I have been aware of this but yet to find a sutable solution for this. I'd be reluctant to put in a hack when a proper fix can be found.

thiver commented 10 years ago

It is indeed just a hack until I can remove it :-)

WanWizard commented 9 years ago

There is currently no reliable way to detect whether or not the object is the first revision, and any solution we can come up with requires a significant change with BC implications. Moving this to ORM v2.