Prepares a table reference for lookup.

Ensures all reference keys are set and properly formatted.

@param Zend_Db_Table_Abstract $dependentTable
@param Zend_Db_Table_Abstract $parentTable
@param string                 $ruleKey
@return array
979020
protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
    {
        $parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
        $map = $dependentTable->getReference($parentTableName, $ruleKey);

        if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
            $parentInfo = $parentTable->info();
            $map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
        }

        $map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
        $map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];

        return $map;
    }
884540
public function getForeignKeyFor(string $localColumn, string $relatedTableName, string $relatedColumn) : ForeignKey
    {
        foreach ($this->foreignKeys as $foreignKey) {
            if ($foreignKey->getLocalColumnNames() === [$localColumn] && $foreignKey->getReferencedTableName() === $relatedTableName && $foreignKey->getReferencedColumnNames() === [$relatedColumn]) {
                return $foreignKey;
            }
        }
        
        throw InvalidArgumentException::format('Cannot find matching foreign key');
    }
1328176
protected function findTableTransferByRelation(array $relationTable, array $tableTransfers): PropelSchemaTableTransfer
    {
        $tableName = $relationTable['foreignTable'];

        $tableTransfer = $tableTransfers[$tableName] ?? new PropelSchemaTableTransfer();

        if ($tableTransfer->getTableName() === null) {
            $tableTransfer->setTableName($tableName);
        }

        $tableTransferPhpName = $tableTransfer->getPhpName();
        $phpName = $relationTable['phpName'];

        if ($tableTransferPhpName === null && $phpName !== null) {
            $tableTransfer->setPhpName($phpName);
        }

        return $tableTransfer;
    }
929226
protected function getJoinClause(Model $parent, Relation $relation, $table, $type)
    {
        list($fk, $pk) = $this->getJoinKeys($relation);

        $join = (new Join($this->query, $type, $table))->on($fk, '=', $pk);

        if (in_array(SoftDeletes::class, class_uses_recursive($relation->getRelated()))) {
            $join->whereNull($relation->getRelated()->getQualifiedDeletedAtColumn());
        }

        if ($relation instanceof MorphOneOrMany) {
            $join->where($relation->getQualifiedMorphType(), '=', $parent->getMorphClass());
        } elseif ($relation instanceof MorphToMany || $relation instanceof MorphByMany) {
            $join->where($relation->getMorphType(), '=', $parent->getMorphClass());
        }

        return $join;
    }
1223760
public function cgetAction(Request $request, $parentId)
    {
        if ($request->get('flat') == 'true') {
            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->get('sulu_core.doctrine_rest_helper');

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            $listBuilder = $factory->create(self::$entityName);

            $fieldDescriptors = $this->getProductVariantManager()->retrieveFieldDescriptors($this->getLocale($request));

            $restHelper->initializeListBuilder(
                $listBuilder,
                $fieldDescriptors
            );

            $listBuilder->where($fieldDescriptors['parent'], $parentId);
            $listBuilder->addGroupBy($fieldDescriptors['id']);

            // Only add group by id if categories are processed.
            $fieldsParam = $request->get('fields');
            $fields = explode(',', $fieldsParam);
            if (isset($filter['categories'])
                || !$fieldsParam
                || array_search('categories', $fields) !== false
            ) {
                $listBuilder->addGroupBy($fieldDescriptors['id']);
            }

            $list = new ListRepresentation(
                $listBuilder->execute(),
                self::$entityKey,
                'get_product_variants',
                array_merge(
                    $request->query->all(),
                    [
                        'parentId' => $parentId,
                    ]
                ),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
        } else {
            $list = new CollectionRepresentation(
                $this->getProductManager()->findAllByLocale($this->getLocale($request)),
                self::$entityKey
            );
        }

        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
1257685
public function getInsertRecords(Model $currentParent, array $insertedPKs)
    {
        $table = $this->relation->getTable();

        $bulkInsertRecords = [];

        foreach ($this->pickRelatedIds($insertedPKs) as $relatedId) {
            $relatedKeyArray = [$this->getRelatedKeyName() => $relatedId];

            if ($this->relation instanceof MorphToMany) {
                $relatedKeyArray[$this->relation->getMorphType()] = $this->relation->getRelated()->getMorphClass();
            }

            $bulkInsertRecords[] = array_merge($relatedKeyArray, $this->getExtraAttributes($insertedPKs, $currentParent));
        }

        return [$table, $bulkInsertRecords, $this->getForeignKeyName()];
    }
453816
protected function _prepareWholeData($ruleKey, array $data, $function)
    {
        foreach ($data as $key => $value) {
            if (preg_match($ruleKey, $key)) {
                $data[$key] = $this->_callUserFunction($function, $key, $value, null);
            }
        }

        return $data;
    }
97445
public function addNew($childName, $parentName, $parentKeyFields)
    {
        // if there is no parent set yet, cant show a button that wont work.
        foreach ($parentKeyFields as $key => $val) {
            if (!trim($val)) {
                return '';
            }
        }

        $elements = array(
            'parent_name' => $parentName,
            'child_name'  => $childName,
        );

        $submitButton = array(
            'name' => 'submit',
            'type' => 'Zend\Form\Element\Submit',
            'attributes' => array(
                'value' => ' + ' . $this->labels[$childName],
            ),
        );

        $form = new \SpeckCatalog\Form\AddChild;
        $form->addElements($elements)
            ->addParent($parentKeyFields);
        $form->add($submitButton);

        $view = $this->getView();
        return $view->render($this->partialDir . 'add', array('addForm' => $form));
    }
738527
protected static function addAlwaysFields($fieldObject, array &$select, $parentTable, $forRelation = false)
    {
        if(isset($fieldObject->config['always']))
        {
            $always = $fieldObject->config['always'];

            if(is_string($always))
            {
                $always = explode(',', $always);
            }

            // Get as 'field' => true
            foreach($always as $field)
            {
                self::addFieldToSelect($field, $select, $parentTable, $forRelation);
            }
        }
    }
626196
private function formJoin($query, $parentTable, $relatedTable, $parentPrimaryKey, $relatedPrimaryKey)
    {
        $joinType = config('columnsortable.join_type', 'leftJoin');

        return $query->select($parentTable.'.*')->{$joinType}($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey);
    }
437396
public function isParentOf($toolKey, $parentKey, $data = null)
    {
        $data = is_null($data) ? $this->getToolSectionMap() : $data;

        foreach ($data as $idx => $tool) {
            if ($tool['key'] === $toolKey) {
                $this->sectionParent = $tool['parent'];
            }

            if (!empty($tool['children']) && $tool['key'] !== $toolKey) {
                $this->isParentOf($toolKey, $parentKey, $tool['children']);
            }
        }

        return $this->sectionParent == $parentKey;
    }
252596
protected final function _rowIsParentRow($parentRow)
    {
        $id = $this->_getIdByParentRow($parentRow);
        if ($parentRow && !$parentRow->{$parentRow->getModel()->getPrimaryKey()}) {
            //remember _createdRows, because once it is saved it will have an id and we can't compare it to $id anymore
            $this->_createdRows[] = $parentRow;
        }
        if ($parentRow && !$parentRow instanceof Kwf_Model_FnF_Row
            && $parentRow->getModel()->isEqual($this->_model)
        ) {
            if ($parentRow->{$parentRow->getModel()->getPrimaryKey()} == $id) {
                return true;
            }
            if (!$id && in_array($parentRow, $this->_createdRows, true)) {
                return true;
            }
        }
        return false;
    }
884383
public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
    {
        if (is_null($relation)) {
            $relation = $this->getBelongsToManyCaller();
        }

        $foreignKey = $foreignKey ?: $this->getForeignKey();

        $instance = new $related;

        $otherKey = $otherKey ?: $instance->getForeignKey();

        if (is_null($table)) {
            $table = $this->joiningTable($related);
        }

        $query = $instance->newQuery();

        return new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation);
    }
74244
public function findRootParentRecursively(string $parentProperty, string $table, Model $instance, bool $returnInstanceIfNoParent = true)
    {
        if (!$instance || !$instance->{$parentProperty}
            || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $returnInstanceIfNoParent ? $instance : null;
        }

        return $this->findRootParentRecursively($parentProperty, $table, $parentInstance);
    }
1045887
public function byParentByFolderNameAndByOrganization($parentId , $parent_name , $organizationId, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->File->setConnection($databaseConnectionName)
      ->where('type', '=', 'C')
      ->where('parent_file_id', '=' , $parentId)
      ->where('name', '=', $parent_name)
      ->where('organization_id', '=', $organizationId)
      ->get();
  }
380452
public static function disableByParent( $parentId, $parentType ) {

		$tableName = static::tableName();

		// Disable all mappings
		$query		= "UPDATE $tableName SET `active`=0 WHERE `parentType`='$parentType' AND `parentId`=$parentId";
		$command	= Yii::$app->db->createCommand( $query );

		$command->execute();
	}
780651
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());

        $query->join($this->throughChild->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->ownerKey);

        if ($this->throughChildSoftDeletes()) {
            $query->whereNull($this->throughChild->getQualifiedDeletedAtColumn());
        }

        $query->getModel()->setTable($hash);

        return $query->whereColumn(
            $hash.'.'.$query->getModel()->qualifyColumn($this->secondKey), '=', $this->getQualifiedSecondOwnerKeyName()
        );
    }