Enables foreign key support.
184186
def _connect(dbapi_connection, connection_record):
    """"""

    # If back end is sqlite
    if type(dbapi_connection) is sqlite3.Connection:

        # Respect foreign key constraints by default
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON")
        cursor.close()
380184
public function addConstraints()
    {
        if (static::$constraints) {
            $table = $this->related->getTable();

            $this->query->where($table.'.'.$this->otherKey, '=', $this->parent->{$this->foreignKey});
        }
    }
464388
def foreign_keys(self):
        
        foreign_keys = self.__current_descriptor.get('foreignKeys', [])
        for key in foreign_keys:
            key.setdefault('fields', [])
            key.setdefault('reference', {})
            key['reference'].setdefault('resource', '')
            key['reference'].setdefault('fields', [])
            if not isinstance(key['fields'], list):
                key['fields'] = [key['fields']]
            if not isinstance(key['reference']['fields'], list):
                key['reference']['fields'] = [key['reference']['fields']]
        return foreign_keys
123323
def _set_join(self, query=None):
        
        if not query:
            query = self._query

        foreign_key = '%s.%s' % (self._related.get_table(), self._second_key)

        query.join(self._parent.get_table(), self.get_qualified_parent_key_name(), '=', foreign_key)
1352080
public function enableForeignKeys()
    {
        $this->getDisconnectRetry()->run(function () {
            $this->execute($this->_driver->enableForeignKeySQL())->closeCursor();
        });
    }
1070852
final protected function setForeignKey(array $rows, string $foreignKey, $value)
    {
        foreach ($rows as $row) {
            $row->setColumn($foreignKey, $value);
        }
    }
772874
def add_foreign_keys_as_attributes
      @@reflections[self.class.name.to_sym][:belongs_to].each do |klass|
        add_attribute klass.to_s.foreign_key.to_sym
      end
    end
192825
public function linkTo($key, $model, $foreign): void
    {
        Relations::setRelation($this->model, $key, $model, $foreign);
    }
1286269
function(r) {
					var rr = {};
					if (typeof r[col.columnid] === 'undefined') {
						return true;
					}
					rr[fk.columnid] = r[col.columnid];
					var addr = fktable.pk.onrightfn(rr);
					//						console.log(r, rr, addr);
					//						console.log(fktable.uniqs[fktable.pk.hh][addr]);
					if (!fktable.uniqs[fktable.pk.hh][addr]) {
						throw new Error(
							'Foreign key "' +
								r[col.columnid] +
								'" is not found in table ' +
								fktable.tableid
						);
					}
					return true;
				}
927772
def remove_foreign_key(self, name):
        
        name = self._normalize_identifier(name)

        if not self.has_foreign_key(name):
            raise ForeignKeyDoesNotExist(name, self._name)

        del self._fk_constraints[name]
1264811
static function TableKeyHasMany($table, $tablePKey, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
	{
		if (!is_array($tablePKey)) {
			$tablePKey = array($tablePKey);
		}
		$ar = new ADODB_Active_Record($table,$tablePKey);
		$ar->hasMany($foreignRef, $foreignKey, $foreignClass);
	}
105545
def attach_foreignkey(objects, field, related=[], database=None):
    

    if not objects:
        return

    if database is None:
        database = list(objects)[0]._state.db

    is_foreignkey = isinstance(field, SingleRelatedObjectDescriptor)

    if not is_foreignkey:
        field = field.field
        accessor = '_%s_cache' % field.name
        model = field.rel.to
        lookup = 'pk'
        column = field.column
        key = lookup
    else:
        accessor = field.cache_name
        field = field.related.field
        model = field.model
        lookup = field.name
        column = 'pk'
        key = field.column

    objects = [o for o in objects if (related or getattr(o, accessor, False) is False)]

    if not objects:
        return

    # Ensure values are unique, do not contain already present values, and are not missing
    # values specified in select_related
    values = distinct(filter(None, (getattr(o, column) for o in objects)))
    if values:
        qs = model.objects.filter(**{'%s__in' % lookup: values})
        if database:
            qs = qs.using(database)
        if related:
            qs = qs.select_related(*related)

        queryset = queryset_to_dict(qs, key=key)
    else:
        queryset = {}

    for o in objects:
        setattr(o, accessor, queryset.get(getattr(o, column)))
688358
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
    {
        $this->output->createForeignKey($fkConstraint, $localTable);
    }
1250359
def get_foreign_key_referential_action_sql(self, action):
        
        action = action.upper()
        if action not in [
            "CASCADE",
            "SET NULL",
            "NO ACTION",
            "RESTRICT",
            "SET DEFAULT",
        ]:
            raise DBALException("Invalid foreign key action: %s" % action)

        return action
76073
def setup(self):
    
    cmds = [
      """
        create table if not exists relations (
          id integer not null primary key,
          name text not null unique,
          completed_at datetime
        );
      """,
      """
        create table if not exists transfers (
          relation_id integer not null references relations (id) on delete cascade,
          old_id text not null,
          new_id text,
          primary key (relation_id, old_id)
        );
      """,
      """
        create index if not exists transfers_relation_id_idx on transfers (relation_id);
      """
    ]

    for cmd in cmds:
      self.data_access.execute(cmd)
    self.data_access.commit()
    return self
433142
def _set_foreign_attributes_for_create(self, model):
        
        model.set_attribute(self.get_plain_foreign_key(), self.get_parent_key())

        model.set_attribute(self.get_plain_morph_type(), self._morph_class)
727058
def foreign_key(name)
      attr = schema.foreign_key(name.dataset)

      if attr
        attr.name
      else
        :"#{Inflector.singularize(name.dataset)}_id"
      end
    end