private function _computePkDiff($initialRelations, $updatedRelations, $forceSave = false)
    {
        // Compute differences between initial relations and the current ones
        $oldPks = ArrayHelper::getColumn($initialRelations, function (BaseActiveRecord $model) {
            return implode('-', $model->getPrimaryKey(true));
        });
        $newPks = ArrayHelper::getColumn($updatedRelations, function (BaseActiveRecord $model) {
            return implode('-', $model->getPrimaryKey(true));
        });
        if ($forceSave) {
            $addedPks = $newPks;
            $deletedPks = $oldPks;
        } else {
            $identicalPks = array_intersect($oldPks, $newPks);
            $addedPks = array_values(array_diff($newPks, $identicalPks));
            $deletedPks = array_values(array_diff($oldPks, $identicalPks));
        }
        return [$addedPks, $deletedPks];
    }
private function _computePkDiff($initialRelations, $updatedRelations, $forceSave = false)
    {
        // Compute differences between initial relations and the current ones
        $oldPks = ArrayHelper::getColumn($initialRelations, function (BaseActiveRecord $model) {
            return implode('-', $model->getPrimaryKey(true));
        });
        $newPks = ArrayHelper::getColumn($updatedRelations, function (BaseActiveRecord $model) {
            return implode('-', $model->getPrimaryKey(true));
        });
        if ($forceSave) {
            $addedPks = $newPks;
            $deletedPks = $oldPks;
        } else {
            $identicalPks = array_intersect($oldPks, $newPks);
            $addedPks = array_values(array_diff($newPks, $identicalPks));
            $deletedPks = array_values(array_diff($oldPks, $identicalPks));
        }
        return [$addedPks, $deletedPks];
    }
private function _computePkDiff ( $ initialRelations , $ updatedRelations , $ forceSave = false ) { // Compute differences between initial relations and the current ones $ oldPks = ArrayHelper :: getColumn ( $ initialRelations , function ( BaseActiveRecord $ model ) { return implode ( '-' , $ model -> getPrimaryKey ( true ) ) ; } ) ; $ newPks = ArrayHelper :: getColumn ( $ updatedRelations , function ( BaseActiveRecord $ model ) { return implode ( '-' , $ model -> getPrimaryKey ( true ) ) ; } ) ; if ( $ forceSave ) { $ addedPks = $ newPks ; $ deletedPks = $ oldPks ; } else { $ identicalPks = array_intersect ( $ oldPks , $ newPks ) ; $ addedPks = array_values ( array_diff ( $ newPks , $ identicalPks ) ) ; $ deletedPks = array_values ( array_diff ( $ oldPks , $ identicalPks ) ) ; } return [ $ addedPks , $ deletedPks ] ; }
Compute the difference between two set of records using primary keys "tokens"
If third parameter is set to true all initial related records will be marked for removal even if their
properties did not change. This can be handy in a many-to-many relation_ involving a junction table.
@param BaseActiveRecord[] $initialRelations
@param BaseActiveRecord[] $updatedRelations
@param bool $forceSave
@return array
Compute the difference between two set of records using primary keys tokens If third parameter is set to true all initial related records will be marked for removal even if their properties did not change . This can be handy in a many - to - many relation_ involving a junction table .