Add a reference to the reference map

@param string $ruleKey
@param string|array $columns
@param string $refTableClass
@param string|array $refColumns
@param string $onDelete
@param string $onUpdate
@return Zend_Db_Table_Abstract
485501
public function addReference($ruleKey, $columns, $refTableClass, $refColumns,
                                 $onDelete = null, $onUpdate = null)
    {
        $reference = array(self::COLUMNS         => (array) $columns,
                           self::REF_TABLE_CLASS => $refTableClass,
                           self::REF_COLUMNS     => (array) $refColumns);

        if (!empty($onDelete)) {
            $reference[self::ON_DELETE] = $onDelete;
        }

        if (!empty($onUpdate)) {
            $reference[self::ON_UPDATE] = $onUpdate;
        }

        $this->_referenceMap[$ruleKey] = $reference;

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

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

        if ($this->throughParentSoftDeletes()) {
            $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
        }

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

        return $query->select($columns)->whereColumn(
            $parentQuery->getQuery()->from.'.'.$this->localKey, '=', $this->getQualifiedFirstKeyName()
        );
    }
580467
public function populate($relatedModel, $ruleKey = null) {
        // Sanity check: does the model have a reference to the
        // given model in the first place?
        // This will throw an exception if not.
        $relatedModel = $relatedModel instanceof Garp_Model_Db ? get_class($relatedModel) : $relatedModel;
        $relatedModel = (substr($relatedModel, 0, 6) !== 'Model_' ? 'Model_' : '') . $relatedModel;
        $ref = $this->_model->getReference($relatedModel, $ruleKey);
        $locales = Garp_I18n::getLocales();
        foreach ($locales as $locale) {
            $factory = new Garp_I18n_ModelFactory($locale);
            $localizedModel = $factory->getModel($relatedModel);
            $localizedModelName = get_class($localizedModel);
            $cleanLocalizedName = $localizedModel->getNameWithoutNamespace();
            $this->_model->addReference(
                $cleanLocalizedName,
                $ref[Zend_Db_Table_Abstract::COLUMNS],
                $localizedModelName,
                $ref[Zend_Db_Table_Abstract::REF_COLUMNS]
            );
        }
        return $this;
    }
310314
function setReference( $table, $name, $key ) {

        $this->references[ $table ][ $name ] = $key;

        return $this;

    }
1175436
protected final function _duplicateDependentModel($newRow, $rule, $select = array())
    {
        $rowset = $this->getChildRows($rule, $select);
        foreach ($rowset as $row) {
            $ref = $row->getModel()->getReferenceByModelClass(get_class($this->getModel()), null);
            $data = array();
            $data[$ref['column']] = $newRow->{$this->_getPrimaryKey()};
            $row->duplicate($data);
        }
    }
1103918
protected function addRule($key, $rules)
    {
        if ($this->shouldSanitize($key)) {
            throw new InvalidArgumentException(sprintf(
                'Sanitation rules are already defined for field [%s]', $key
            ));
        }

        $this->rules[$key] = $this->buildRules($rules);
    }
1306895
public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1)
    {
        if (!is_numeric($pBefore)) {
            $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
            $objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this);
        } else {
            throw new PHPExcel_Exception("Column references should not be numeric.");
        }
        return $this;
    }
352106
public static function createFromOrderReferenceId(Connection $dbal, $amazon_order_reference_id)
    {
        $data = $dbal->fetchAll(
            'select * from '.self::PERSIST_TABLE.' WHERE `amazon_order_reference_id` = ? ORDER BY `cmsident`',
            array($amazon_order_reference_id)
        );
        $manager = self::createFromRecordList($data);

        if (null === $manager) {
            throw new \InvalidArgumentException("unable to find an an id mapper object based on the amazonOrderReferenceId [{$amazon_order_reference_id}]");
        }

        return $manager;
    }
295981
private function GetConstraintRules($constraintName, ConstraintRule &$onUpdate = null, ConstraintRule &$onDelete = null)
    {
        $sql = new Sql\Builder($this);
        $tbl = $sql->Table('information_schema.REFERENTIAL_CONSTRAINTS', array('CONSTRAINT_NAME', 'UPDATE_RULE', 'DELETE_RULE'));
       
        $where = $sql->Equals($tbl->Field('CONSTRAINT_NAME'), $sql->Value($constraintName));
        $selectList = $sql->SelectList($tbl->Field('UPDATE_RULE'));
        $selectList->Add($tbl->Field('DELETE_RULE'));
        $select = $sql->Select(false, $selectList, $tbl, $where);
        $reader = $this->ExecuteQuery((string) $select);
        if ($reader->Read())
        {
            $onUpdate = ConstraintRule::ByValue($reader->ByName('UPDATE_RULE'));
            $onDelete = ConstraintRule::ByValue($reader->ByName('DELETE_RULE'));
        }
    }
63379
public function addOneToOne($schema, $col = null, $foreign_id = null, $on_delete = null, $on_update = null, $name = null, $one = null)
  {
    $m = $this->getManager();
    $s = $schema instanceof Schema ? $schema : $m->getSchema($schema, true);
    $n = $name ?: $s->getName();

    if (!$foreign_id = $foreign_id ?: $s->getPrimaryKey()) {
      Exception::ThrowError(Exception::PK_NOT_SET, $s->getName());
    }

    $col = $col ?: StaticStringy::underscored($s->getItemClass(false) . '_id');

    $this->addInt($col, null, true, 11);
    $this->addForeignKey($col, $s, $foreign_id, $on_delete, $on_update);

    $this->relations[$n] = array(
      'type'       => static::RELATION_ONE_TO_ONE,
      'column'     => $col,
      'schema'     => $s,
      'foreign_id' => $foreign_id,
      'name'       => $n,
      'one'        => $one ?: $s->getItemClass(false),
    );

    return $this;
  }
499176
public function addJoinColumn(
        $relation,
        $joinColumn = null,
        $referenceColumn = null,
        $nullable = false,
        $unique = false,
        $onDelete = null,
        $columnDefinition = null
    ) {
        $joinColumn = new JoinColumn(
            $this->getNamingStrategy(),
            $relation,
            $joinColumn,
            $referenceColumn,
            $nullable,
            $unique,
            $onDelete,
            $columnDefinition
        );

        $this->pushJoinColumn($joinColumn);

        return $this;
    }
1233335
public function foreignKey($foreignKey, $references = 'id', $unique = false)
    {
        return $this->joinColumn($foreignKey, $references, $unique);
    }
186668
public static function dropForeignKey($table, $columns, $refTable, $refColumns)
    {
        $name = static::createForeignKeyName($table, $columns, $refTable);
        $fks = Yii::$app->db->schema->getTableSchema($table)->foreignKeys;
        $search = array_merge([$refTable], array_combine((array)$columns, (array)$refColumns));
        if (!in_array($search, $fks)) {
            return true;
        }
        return Yii::$app->db->createCommand()->dropForeignKey($name, $table)->execute();
    }
1020892
protected function foreignRelationship(
        string $column,
        string $referredClass,
        bool $cascadeDelete = false
    ): Closure {
        return function (
            Table $table,
            MigrationContextInterface $context
        ) use (
            $column,
            $referredClass,
            $cascadeDelete
        ) {
            $tableName    = $this->getTableNameForClass($referredClass);
            $pkName       = $this->getModelSchemas()->getPrimaryKey($referredClass);
            $columnType   = $this->getModelSchemas()->getAttributeType($context->getModelClass(), $column);
            $columnLength = $columnType === Type::STRING ?
                $this->getModelSchemas()->getAttributeLength($context->getModelClass(), $column) : null;

            $closure = $this->foreignColumn($column, $tableName, $pkName, $columnType, $columnLength, $cascadeDelete);

            return $closure($table, $context);
        };
    }
829526
public function addJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null)
    {
        $this->joinColumns[] = array(
            'name' => $columnName,
            'referencedColumnName' => $referencedColumnName,
            'nullable' => $nullable,
            'unique' => $unique,
            'onDelete' => $onDelete,
            'columnDefinition' => $columnDef,
        );
        return $this;
    }
32888
final public function update(array $datas, $noApplyPrimaryKey = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0])) {
            $datas = [$datas];
         }

         $this->connection();
         $this->columns();
         
         $this->last_sql = [];
         $this->placeholder_data = [];

         $where = $this->where;
         $whereTemp = str_replace('WHERE', '', $this->where);

         $rowCount = [];
         foreach ($datas as $data) {
            $placeholder = [];
            $isID = NULL;
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  if($this->primaryKey==$column && $noApplyPrimaryKey===false) {
                     $isID = $data[$column];
                  } 
                  else {
                     $placeholder[$column] = "{$column}=NULL";
                     if ( gettype($data[$column])==='boolean' )
                        $placeholder[$column] = $data[$column] ? "{$column}=TRUE" : "{$column}=FALSE";
                     elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                        $placeholder[$column] = "{$column}=?";
                        $this->placeholder_data[] = $data[$column];
                     }
                  }
               }
            }


            if($isID!==NULL) {
               $this->where = '';
               $this->where( $this->primaryKey, '=', $isID );
               if (trim($whereTemp)) {
                  $where = $this->where .' AND '. $whereTemp;
               }
               else {
                  $where = $this->where;
               }
            }

            $schema = '';
            if($this->driver=='pgsql' && $this->schema) {
               if (!preg_match('/\./', $this->table)) {
                  $schema = $this->schema ? $this->schema.'.' : '';	
               }
            }

            $placeholders = implode(",", $placeholder);
            $this->last_sql[] = $this->sql = "UPDATE {$schema}{$this->table} SET {$placeholders} {$where}";

            // $this->fetch(false);
            $this->fetch();

            $rowCount[] = $this->rowCount;

            $this->reset();

            if ( $this->tableOrig!==null ) {
               $this->table = $this->tableOrig;
            }

            $error = $this->error();
            if($error['message']) return false;
         }
         if ( count( $rowCount )===1 ) {
            $this->rowCount = $rowCount[0];
         }
         else {
            $this->rowCount = $rowCount;
         }
         
         return true;
      }
      return false;
   }
1047323
protected function addRefFKAdd(&$script, ForeignKey $refFK)
    {
        $tblFK = $refFK->getTable();

        $className = $this->getClassNameFromTable($refFK->getTable());

        if ($tblFK->getChildrenColumn()) {
            $className = $this->getClassNameFromTable($refFK->getTable(), true);
        }

        $collName = $this->getRefFKCollVarName($refFK);

        $scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, $plural = true)) . "ScheduledForDeletion";

        $script .= "
    /**
     * Method called to associate a $className object to this object
     * through the $className foreign key attribute.
     *
     * @param  $className \$l $className
     * @return \$this|".$this->getObjectClassName(true)." The current object (for fluent API support)
     */
    public function add".$this->getRefFKPhpNameAffix($refFK, false)."($className \$l)
    {
        if (\$this->$collName === null) {
            \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "();
            \$this->{$collName}Partial = true;
        }

        if (!\$this->{$collName}->contains(\$l)) {
            \$this->doAdd" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(\$l);

            if (\$this->{$scheduledForDeletion} and \$this->{$scheduledForDeletion}->contains(\$l)) {
                \$this->{$scheduledForDeletion}->remove(\$this->{$scheduledForDeletion}->search(\$l));
            }
        }

        return \$this;
    }
";
    }