protected function syncRelatedFields(
        IdProperty $newProp,
        PropertyField $newField,
        IdProperty $oldProp,
        PropertyField $oldField
    ) {
        unset($newProp, $oldProp, $oldField);

        $cli = $this->climate();
        if (!$this->quiet()) {
            $cli->br();
            $cli->comment('Syncing new IDs to pivot table.');
        }

        $pivot  = $this->pivotModel();
        $attach = $this->targetModel();

        $pivotSource  = $pivot->source();
        $pivotTable   = $pivotSource->table();

        $attachSource = $attach->source();
        $attachTable  = $attachSource->table();

        $db = $attachSource->db();

        $binds = [
            // Join Model
            '%pivotTable'   => $pivotTable,
            '%objectType'   => 'object_type',
            '%objectId'     => 'object_id',
            '%targetId'     => 'attachment_id',

            // Attachment Model
            '%targetTable'  => $attachTable,
            '%targetType'   => 'type',
            '%newKey'       => $newField->ident(),
            '%oldKey'       => $attach->key(),
        ];

        // Update simple object → attachment associations
        $sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%targetId` = a.`%oldKey`
                SET p.`%targetId` = a.`%newKey`;';
        $db->query(strtr($sql, $binds));

        // Update nested attachment → attachment associations
        $sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType`
                SET p.`%objectId` = a.`%newKey`;';
        $db->query(strtr($sql, $binds));

        return $this;
    }
protected function syncRelatedFields(
        IdProperty $newProp,
        PropertyField $newField,
        IdProperty $oldProp,
        PropertyField $oldField
    ) {
        unset($newProp, $oldProp, $oldField);

        $cli = $this->climate();
        if (!$this->quiet()) {
            $cli->br();
            $cli->comment('Syncing new IDs to pivot table.');
        }

        $pivot  = $this->pivotModel();
        $attach = $this->targetModel();

        $pivotSource  = $pivot->source();
        $pivotTable   = $pivotSource->table();

        $attachSource = $attach->source();
        $attachTable  = $attachSource->table();

        $db = $attachSource->db();

        $binds = [
            // Join Model
            '%pivotTable'   => $pivotTable,
            '%objectType'   => 'object_type',
            '%objectId'     => 'object_id',
            '%targetId'     => 'attachment_id',

            // Attachment Model
            '%targetTable'  => $attachTable,
            '%targetType'   => 'type',
            '%newKey'       => $newField->ident(),
            '%oldKey'       => $attach->key(),
        ];

        // Update simple object → attachment associations
        $sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%targetId` = a.`%oldKey`
                SET p.`%targetId` = a.`%newKey`;';
        $db->query(strtr($sql, $binds));

        // Update nested attachment → attachment associations
        $sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType`
                SET p.`%objectId` = a.`%newKey`;';
        $db->query(strtr($sql, $binds));

        return $this;
    }
protected function syncRelatedFields ( IdProperty $ newProp , PropertyField $ newField , IdProperty $ oldProp , PropertyField $ oldField ) { unset ( $ newProp , $ oldProp , $ oldField ) ; $ cli = $ this -> climate ( ) ; if ( ! $ this -> quiet ( ) ) { $ cli -> br ( ) ; $ cli -> comment ( 'Syncing new IDs to pivot table.' ) ; } $ pivot = $ this -> pivotModel ( ) ; $ attach = $ this -> targetModel ( ) ; $ pivotSource = $ pivot -> source ( ) ; $ pivotTable = $ pivotSource -> table ( ) ; $ attachSource = $ attach -> source ( ) ; $ attachTable = $ attachSource -> table ( ) ; $ db = $ attachSource -> db ( ) ; $ binds = [ // Join Model '%pivotTable' => $ pivotTable , '%objectType' => 'object_type' , '%objectId' => 'object_id' , '%targetId' => 'attachment_id' , // Attachment Model '%targetTable' => $ attachTable , '%targetType' => 'type' , '%newKey' => $ newField -> ident ( ) , '%oldKey' => $ attach -> key ( ) , ] ; // Update simple object → attachment associations $ sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%targetId` = a.`%oldKey`
                SET p.`%targetId` = a.`%newKey`;' ; $ db -> query ( strtr ( $ sql , $ binds ) ) ; // Update nested attachment → attachment associations $ sql = 'UPDATE `%pivotTable` AS p
                JOIN `%targetTable` AS a
                ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType`
                SET p.`%objectId` = a.`%newKey`;' ; $ db -> query ( strtr ( $ sql , $ binds ) ) ; return $ this ; }
Sync the new primary keys to pivot table.

@param  IdProperty    $newProp  The new ID property.
@param  PropertyField $newField The new ID field.
@param  IdProperty    $oldProp  The previous ID property.
@param  PropertyField $oldField The previous ID field.
@throws InvalidArgumentException If the new property does not implement the proper mode.
@return self
Sync the new primary keys to pivot table .