src/ORM/DataObject.php
protected function duplicateRelations($sourceObject, $destinationObject, $relations)
    {
        // Get list of duplicable relation types
        $manyMany = $sourceObject->manyMany();
        $hasMany = $sourceObject->hasMany();
        $hasOne = $sourceObject->hasOne();
        $belongsTo = $sourceObject->belongsTo();

        // Duplicate each relation based on type
        foreach ($relations as $relation) {
            switch (true) {
                case array_key_exists($relation, $manyMany): {
                    $this->duplicateManyManyRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $hasMany): {
                    $this->duplicateHasManyRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $hasOne): {
                    $this->duplicateHasOneRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $belongsTo): {
                    $this->duplicateBelongsToRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                default: {
                    $sourceType = get_class($sourceObject);
                    throw new InvalidArgumentException(
                        "Cannot duplicate unknown relation {$relation} on parent type {$sourceType}"
                    );
                }
            }
        }
    }
protected function duplicateRelations($sourceObject, $destinationObject, $relations)
    {
        // Get list of duplicable relation types
        $manyMany = $sourceObject->manyMany();
        $hasMany = $sourceObject->hasMany();
        $hasOne = $sourceObject->hasOne();
        $belongsTo = $sourceObject->belongsTo();

        // Duplicate each relation based on type
        foreach ($relations as $relation) {
            switch (true) {
                case array_key_exists($relation, $manyMany): {
                    $this->duplicateManyManyRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $hasMany): {
                    $this->duplicateHasManyRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $hasOne): {
                    $this->duplicateHasOneRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                case array_key_exists($relation, $belongsTo): {
                    $this->duplicateBelongsToRelation($sourceObject, $destinationObject, $relation);
                    break;
                }
                default: {
                    $sourceType = get_class($sourceObject);
                    throw new InvalidArgumentException(
                        "Cannot duplicate unknown relation {$relation} on parent type {$sourceType}"
                    );
                }
            }
        }
    }
protected function duplicateRelations ( $ sourceObject , $ destinationObject , $ relations ) { // Get list of duplicable relation types $ manyMany = $ sourceObject -> manyMany ( ) ; $ hasMany = $ sourceObject -> hasMany ( ) ; $ hasOne = $ sourceObject -> hasOne ( ) ; $ belongsTo = $ sourceObject -> belongsTo ( ) ; // Duplicate each relation based on type foreach ( $ relations as $ relation ) { switch ( true ) { case array_key_exists ( $ relation , $ manyMany ) : { $ this -> duplicateManyManyRelation ( $ sourceObject , $ destinationObject , $ relation ) ; break ; } case array_key_exists ( $ relation , $ hasMany ) : { $ this -> duplicateHasManyRelation ( $ sourceObject , $ destinationObject , $ relation ) ; break ; } case array_key_exists ( $ relation , $ hasOne ) : { $ this -> duplicateHasOneRelation ( $ sourceObject , $ destinationObject , $ relation ) ; break ; } case array_key_exists ( $ relation , $ belongsTo ) : { $ this -> duplicateBelongsToRelation ( $ sourceObject , $ destinationObject , $ relation ) ; break ; } default : { $ sourceType = get_class ( $ sourceObject ) ; throw new InvalidArgumentException ( "Cannot duplicate unknown relation {$relation} on parent type {$sourceType}" ) ; } } } }
Copies the given relations from this object to the destination

@param DataObject $sourceObject the source object to duplicate from
@param DataObject $destinationObject the destination object to populate with the duplicated relations
@param array $relations List of relations
Copies the given relations from this object to the destination