public function onInsertRelation($event)
    {
        $sender = $event->sender;
        /* @var $sender static */
        if ($sender->relationType == static::$relationMutual) {
            $opposite = static::buildOppositeRelation($sender);
            $opposite->off(static::EVENT_AFTER_INSERT, [$opposite, 'onInsertRelation']);
            if (!$opposite->save()) {
                $opposite->recordWarnings();
                throw new IntegrityException('Reverse relation insert failed.');
            }
            $opposite->on(static::EVENT_AFTER_INSERT, [$opposite, 'onInsertRelation']);
        }
    }
public function onInsertRelation($event)
    {
        $sender = $event->sender;
        /* @var $sender static */
        if ($sender->relationType == static::$relationMutual) {
            $opposite = static::buildOppositeRelation($sender);
            $opposite->off(static::EVENT_AFTER_INSERT, [$opposite, 'onInsertRelation']);
            if (!$opposite->save()) {
                $opposite->recordWarnings();
                throw new IntegrityException('Reverse relation insert failed.');
            }
            $opposite->on(static::EVENT_AFTER_INSERT, [$opposite, 'onInsertRelation']);
        }
    }
public function onInsertRelation ( $ event ) { $ sender = $ event -> sender ; /* @var $sender static */ if ( $ sender -> relationType == static :: $ relationMutual ) { $ opposite = static :: buildOppositeRelation ( $ sender ) ; $ opposite -> off ( static :: EVENT_AFTER_INSERT , [ $ opposite , 'onInsertRelation' ] ) ; if ( ! $ opposite -> save ( ) ) { $ opposite -> recordWarnings ( ) ; throw new IntegrityException ( 'Reverse relation insert failed.' ) ; } $ opposite -> on ( static :: EVENT_AFTER_INSERT , [ $ opposite , 'onInsertRelation' ] ) ; } }
The event triggered after insert new relation.
The opposite relation should be inserted without triggering events
simultaneously after new relation inserted,
@param ModelEvent $event
@throws IntegrityException throw if insert failed.
The event triggered after insert new relation . The opposite relation should be inserted without triggering events simultaneously after new relation inserted