private function _getRelatedFks($data, $relation, $modelClass)
    {
        $fks = [];
        if (is_array($data)) {
            // Get the right link definition
            if ($relation->via instanceof BaseActiveRecord) {
                $link = $relation->via->link;
            } elseif (is_array($relation->via)) {
                list($viaName, $viaQuery) = $relation->via;
                $link = $viaQuery->link;
            } else {
                $link = $relation->link;
            }
            // search PK
            foreach ($modelClass::primaryKey() as $modelAttribute) {
                if (isset($data[$modelAttribute])) {
                    $fks[$modelAttribute] = $data[$modelAttribute];
                } elseif ($relation->multiple && !$relation->via) {
                    foreach ($link as $relatedAttribute => $relatedModelAttribute) {
                        if (!isset($data[$relatedAttribute]) && in_array($relatedAttribute, $modelClass::primaryKey())) {
                            $fks[$relatedAttribute] = $this->owner->{$relatedModelAttribute};
                        }
                    }
                } else {
                    $fks = [];
                    break;
                }
            }
            if (empty($fks)) {
                foreach ($link as $relatedAttribute => $modelAttribute) {
                    if (isset($data[$modelAttribute])) {
                        $fks[$modelAttribute] = $data[$modelAttribute];
                    }
                }
            }
        } else {
            $fks = $data;
        }
        return $fks;
    }
private function _getRelatedFks($data, $relation, $modelClass)
    {
        $fks = [];
        if (is_array($data)) {
            // Get the right link definition
            if ($relation->via instanceof BaseActiveRecord) {
                $link = $relation->via->link;
            } elseif (is_array($relation->via)) {
                list($viaName, $viaQuery) = $relation->via;
                $link = $viaQuery->link;
            } else {
                $link = $relation->link;
            }
            // search PK
            foreach ($modelClass::primaryKey() as $modelAttribute) {
                if (isset($data[$modelAttribute])) {
                    $fks[$modelAttribute] = $data[$modelAttribute];
                } elseif ($relation->multiple && !$relation->via) {
                    foreach ($link as $relatedAttribute => $relatedModelAttribute) {
                        if (!isset($data[$relatedAttribute]) && in_array($relatedAttribute, $modelClass::primaryKey())) {
                            $fks[$relatedAttribute] = $this->owner->{$relatedModelAttribute};
                        }
                    }
                } else {
                    $fks = [];
                    break;
                }
            }
            if (empty($fks)) {
                foreach ($link as $relatedAttribute => $modelAttribute) {
                    if (isset($data[$modelAttribute])) {
                        $fks[$modelAttribute] = $data[$modelAttribute];
                    }
                }
            }
        } else {
            $fks = $data;
        }
        return $fks;
    }
private function _getRelatedFks ( $ data , $ relation , $ modelClass ) { $ fks = [ ] ; if ( is_array ( $ data ) ) { // Get the right link definition if ( $ relation -> via instanceof BaseActiveRecord ) { $ link = $ relation -> via -> link ; } elseif ( is_array ( $ relation -> via ) ) { list ( $ viaName , $ viaQuery ) = $ relation -> via ; $ link = $ viaQuery -> link ; } else { $ link = $ relation -> link ; } // search PK foreach ( $ modelClass :: primaryKey ( ) as $ modelAttribute ) { if ( isset ( $ data [ $ modelAttribute ] ) ) { $ fks [ $ modelAttribute ] = $ data [ $ modelAttribute ] ; } elseif ( $ relation -> multiple && ! $ relation -> via ) { foreach ( $ link as $ relatedAttribute => $ relatedModelAttribute ) { if ( ! isset ( $ data [ $ relatedAttribute ] ) && in_array ( $ relatedAttribute , $ modelClass :: primaryKey ( ) ) ) { $ fks [ $ relatedAttribute ] = $ this -> owner -> { $ relatedModelAttribute } ; } } } else { $ fks = [ ] ; break ; } } if ( empty ( $ fks ) ) { foreach ( $ link as $ relatedAttribute => $ modelAttribute ) { if ( isset ( $ data [ $ modelAttribute ] ) ) { $ fks [ $ modelAttribute ] = $ data [ $ modelAttribute ] ; } } } } else { $ fks = $ data ; } return $ fks ; }
Get the related model foreign keys
@param $data
@param $relation
@param BaseActiveRecord $modelClass
@return array
Get the related model foreign keys