add a foreign key field ID
182397
public void addForeignKeyField(int newId)
    {
        if (m_ForeignKeyFields == null)
        {
            m_ForeignKeyFields = new Vector();
        }
        m_ForeignKeyFields.add(new Integer(newId));
    }
1296488
public function addForeignKey(ForeignKey $foreignKey)
    {
        $this->table = $this->table->withForeignKeys(
            array_merge($this->table->getForeignKeys(), [$foreignKey])
        );
    }
17244
def _add_crud(self, model_data, object_type, results):
        
        model = model_registry.get_model(model_data['name'])
        field_name = model_data.get('field')
        verbose_name = model_data.get('verbose_name', model.Meta.verbose_name_plural)
        category = model_data.get('category', settings.DEFAULT_OBJECT_CATEGORY_NAME)
        wf_dict = {"text": verbose_name,
                   "wf": model_data.get('wf', "crud"),
                   "model": model_data['name'],
                   "kategori": category}
        if field_name:
            wf_dict['param'] = field_name
        results[object_type].append(wf_dict)
        self._add_to_quick_menu(wf_dict['model'], wf_dict)
55211
protected function addRelation()
    {
        if ($this->relationType == 'hasAndBelongsToMany')
        {
            $junction = $this->getJunction();

            try
            {
                Validate::table($junction)->exists();
            }
            catch (dbException $e)
            {
                Database::create($junction, [
                    $this->tables['local'] . '_id'   => 'integer',
                    $this->tables['foreign'] . '_id' => 'integer',
                ]);

                $this->insertRelationData($junction, $this->tables['local'], 'hasMany', [
                    'local'   => $this->tables['local'] . '_id',
                    'foreign' => $this->keys['local']
                ]);

                $this->insertRelationData($junction, $this->tables['foreign'], 'hasMany', [
                    'local'   => $this->tables['foreign'] . '_id',
                    'foreign' => $this->keys['foreign']
                ]);
            }
        }
        $this->insertRelationData($this->tables['local'], $this->tables['foreign'], $this->relationType, $this->keys);
    }
231335
public void addForeignKeyField(String newField)
    {
        if (m_ForeignKeyFields == null)
        {
            m_ForeignKeyFields = new Vector();
        }
        m_ForeignKeyFields.add(newField);
    }
518698
public void addForeignkey(String relationName, String remoteTable, List localColumns, List remoteColumns)
    {
        ForeignkeyDef foreignkeyDef = new ForeignkeyDef(relationName, remoteTable);

        // the field arrays have the same length if we already checked the constraints
        for (int idx = 0; idx < localColumns.size(); idx++)
        {
            foreignkeyDef.addColumnPair((String)localColumns.get(idx),
                                        (String)remoteColumns.get(idx));
        }

        // we got to determine whether this foreignkey is already present 
        ForeignkeyDef def = null;

        for (Iterator it = getForeignkeys(); it.hasNext();)
        {
            def = (ForeignkeyDef)it.next();
            if (foreignkeyDef.equals(def))
            {
                return;
            }
        }
        foreignkeyDef.setOwner(this);
        _foreignkeys.add(foreignkeyDef);
    }
354472
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
    {
        if ($table instanceof Table) {
            $table = $table->getQuotedName($this);
        }

        return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
    }
785287
async def expand_foreign_keys(self, database, table, column, values):
        ""
        labeled_fks = {}
        foreign_keys = await self.foreign_keys_for_table(database, table)
        # Find the foreign_key for this column
        try:
            fk = [
                foreign_key for foreign_key in foreign_keys
                if foreign_key["column"] == column
            ][0]
        except IndexError:
            return {}
        label_column = await self.label_column_for_table(database, fk["other_table"])
        if not label_column:
            return {
                (fk["column"], value): str(value)
                for value in values
            }
        labeled_fks = {}
        sql = '''
            select {other_column}, {label_column}
            from {other_table}
            where {other_column} in ({placeholders})
        '''.format(
            other_column=escape_sqlite(fk["other_column"]),
            label_column=escape_sqlite(label_column),
            other_table=escape_sqlite(fk["other_table"]),
            placeholders=", ".join(["?"] * len(set(values))),
        )
        try:
            results = await self.execute(
                database, sql, list(set(values))
            )
        except InterruptedError:
            pass
        else:
            for id, value in results:
                labeled_fks[(fk["column"], id)] = value
        return labeled_fks
208799
def build_relational_field(self, field_name, relation_info):
        
        field_class = self.serializer_related_field
        field_kwargs = get_relation_kwargs(field_name, relation_info)

        to_field = field_kwargs.pop('to_field', None)
        if to_field and not relation_info.related_model._meta.get_field(to_field).primary_key:
            field_kwargs['slug_field'] = to_field
            field_class = self.serializer_related_to_field

        # `view_name` is only valid for hyperlinked relationships.
        if not issubclass(field_class, HyperlinkedRelatedField):
            field_kwargs.pop('view_name', None)

        return field_class, field_kwargs
1326342
protected function addFieldValue()
    {
        if (!$this->isError()) {
            $id = $this->field_value->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
755353
public function addExtraIndices()
    {
        /**
         * A collection of indexed columns. The keys is the column name
         * (concatenated with a comma in the case of multi-col index), the value is
         * an array with the names of the indexes that index these columns. We use
         * it to determine which additional indexes must be created for foreign
         * keys. It could also be used to detect duplicate indexes, but this is not
         * implemented yet.
         * @var array
         */
        $_indices = [];

        $this->collectIndexedColumns('PRIMARY', $this->getPrimaryKey(), $_indices);

        $_tableIndices = array_merge($this->getIndices(), $this->getUnices());
        foreach ($_tableIndices as $_index) {
            $this->collectIndexedColumns($_index->getName(), $_index->getColumns(), $_indices);
        }

        // we're determining which tables have foreign keys that point to this table,
        // since MySQL needs an index on any column that is referenced by another table
        // (yep, MySQL _is_ a PITA)
        $counter = 0;
        foreach ($this->referrers as $foreignKey) {
            $referencedColumns = $foreignKey->getForeignColumnObjects();
            $referencedColumnsHash = $this->getColumnList($referencedColumns);
            if (empty($referencedColumns) || isset($_indices[$referencedColumnsHash])) {
                continue;
            }

            // no matching index defined in the schema, so we have to create one
            $name = sprintf('i_referenced_%s_%s', $foreignKey->getName(), ++$counter);
            if ($this->hasIndex($name)) {
                // if we have already a index with this name, then it looks like the columns of this index have just
                // been changed, so remove it and inject it again. This is the case if a referenced table is handled
                // later than the referencing table.
                $this->removeIndex($name);
            }

            $index = $this->createIndex($name, $referencedColumns);
            // Add this new index to our collection, otherwise we might add it again (bug #725)
            $this->collectIndexedColumns($index->getName(), $referencedColumns, $_indices);
        }

        // we're adding indices for this table foreign keys
        foreach ($this->foreignKeys as $foreignKey) {
            $localColumns = $foreignKey->getLocalColumnObjects();
            $localColumnsHash = $this->getColumnList($localColumns);
            if (empty($localColumns) || isset($_indices[$localColumnsHash])) {
                continue;
            }

            // No matching index defined in the schema, so we have to create one.
            // MySQL needs indices on any columns that serve as foreign keys.
            // These are not auto-created prior to 4.1.2.

            $name = substr_replace($foreignKey->getName(), 'fi_',  strrpos($foreignKey->getName(), 'fk_'), 3);
            if ($this->hasIndex($name)) {
                // if we already have an index with this name, then it looks like the columns of this index have just
                // been changed, so remove it and inject it again. This is the case if a referenced table is handled
                // later than the referencing table.
                $this->removeIndex($name);
            }

            $index = $this->createIndex($name, $localColumns);
            $this->collectIndexedColumns($index->getName(), $localColumns, $_indices);
        }
    }
1072653
private void populateId(EntityMetadata entityMetadata, Table schemaTable, Object entity, Row row)
    {
        FieldDef fieldMetadata;
        FieldValue value;
        String idColumnName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();

        fieldMetadata = schemaTable.getField(idColumnName);

        value = row.get(idColumnName);

        NoSqlDBUtils.get(fieldMetadata, value, entity, (Field) entityMetadata.getIdAttribute().getJavaMember());
    }
1250876
def update_field(uid, post_id=None, tag_id=None, par_id=None):
        '''
        
        '''
        if post_id:
            entry = TabPost2Tag.update(
                post_id=post_id
            ).where(TabPost2Tag.uid == uid)
            entry.execute()

        if tag_id:
            entry2 = TabPost2Tag.update(
                par_id=tag_id[:2] + '00',
                tag_id=tag_id,
            ).where(TabPost2Tag.uid == uid)
            entry2.execute()
        if par_id:
            entry2 = TabPost2Tag.update(
                par_id=par_id
            ).where(TabPost2Tag.uid == uid)
            entry2.execute()
1246052
private void addForeignkeys(ReferenceDescriptorDef refDef, TableDef tableDef)
    {
        if (!refDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_DATABASE_FOREIGNKEY, true))
        {
            // we shall not generate a database foreignkey
            return;
        }

        // a foreignkey is added to the table schema if
        // the referenced table exists (i.e. the referenced type has an associated table)
        // then the foreignkey consists of:
        //   remote table  = table of referenced type
        //   local fields  = foreignkey fields of the reference 
        //   remote fields = primarykeys of the referenced type
        ClassDescriptorDef ownerClassDef      = (ClassDescriptorDef)refDef.getOwner();
        String             targetClassName    = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
        ClassDescriptorDef referencedClassDef = ((ModelDef)ownerClassDef.getOwner()).getClass(targetClassName);

        // we can add a foreignkey only if the target type and all its subtypes either
        // map to the same table or do not map to a table at all
        String tableName = getHierarchyTable(referencedClassDef);

        if (tableName == null)
        {
            return;
        }

        try
        {
            String    name         = refDef.getName();
            ArrayList localFields  = ownerClassDef.getFields(refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY));
            ArrayList remoteFields = referencedClassDef.getPrimaryKeys();

            tableDef.addForeignkey(name, tableName, getColumns(localFields), getColumns(remoteFields));
        }
        catch (NoSuchFieldException ex)
        {
            // won't happen if we already checked the constraints
        }
    }
1074170
private function appendForeignKeyNode(ForeignKey $foreignKey, \DOMNode $parentNode)
    {
        $foreignKeyNode = $parentNode->appendChild($this->document->createElement('foreign-key'));
        $foreignKeyNode->setAttribute('foreignTable', $foreignKey->getForeignTableCommonName());

        if ($schema = $foreignKey->getForeignSchemaName()) {
            $foreignKeyNode->setAttribute('foreignSchema', $schema);
        }

        $foreignKeyNode->setAttribute('name', $foreignKey->getName());

        if ($phpName = $foreignKey->getPhpName()) {
            $foreignKeyNode->setAttribute('phpName', $phpName);
        }

        if ($refPhpName = $foreignKey->getRefPhpName()) {
            $foreignKeyNode->setAttribute('refPhpName', $refPhpName);
        }

        if ($defaultJoin = $foreignKey->getDefaultJoin()) {
            $foreignKeyNode->setAttribute('defaultJoin', $defaultJoin);
        }

        if ($onDeleteBehavior = $foreignKey->getOnDelete()) {
            $foreignKeyNode->setAttribute('onDelete', $onDeleteBehavior);
        }

        if ($onUpdateBehavior = $foreignKey->getOnUpdate()) {
            $foreignKeyNode->setAttribute('onUpdate', $onUpdateBehavior);
        }

        for ($i = 0, $size = count($foreignKey->getLocalColumns()); $i < $size; $i++) {
            $refNode = $foreignKeyNode->appendChild($this->document->createElement('reference'));
            $refNode->setAttribute('local', $foreignKey->getLocalColumnName($i));
            $refNode->setAttribute('foreign', $foreignKey->getForeignColumnName($i));
        }

        foreach ($foreignKey->getVendorInformation() as $vendorInformation) {
            $this->appendVendorInformationNode($vendorInformation, $foreignKeyNode);
        }
    }
359895
public function getAddForeignKeyDDL(ForeignKey $fk)
    {
        if ($fk->isSkipSql() || $fk->isPolymorphic()) {
            return;
        }
        $pattern = "
ALTER TABLE %s ADD %s;
";

        return sprintf($pattern,
            $this->quoteIdentifier($fk->getTable()->getName()),
            $this->getForeignKeyDDL($fk)
        );
    }
631176
def fake_fk(self, field_name):
        
        return self.djipsum_fields().getOrCreateForeignKey(
            model_class=self.model_class(),
            field_name=field_name
        )