Set foreign

@param string|null $foreign

@return Attribute

@throws \InvalidArgumentException
555088
public function setForeign($foreign)
    {
        if (!is_string($foreign) && null !== $foreign) {
            throw new \InvalidArgumentException('The attribute foreign on the class Attribute has to be string or null (' . gettype($foreign) . ('object' === gettype($foreign) ? ' ' . get_class($foreign) : '') . ' given).');
        }

        $this->foreign = $foreign;

        return $this;
    }
1226649
public function set($name, $value=null, $locale=null, $hook=true, $change=true, $silentException=false) {
		if(is_string($name))
			$name = strtolower($name);

		#setting multiple properties at once
		if(is_array($name)) {
			$vars = $name;
			$locale = $value;
			foreach($vars as $name=>$value)
				$this->set($name, $value, $locale, $hook);
			return $this;
		}

		#setting a property multiple translations at once
		if(is_array($locale)) {
			foreach($locale as $one)
				$this->set($name, $value[$one], $one, $hook);
			return $this;
		}

		$this->getDefinition()->processPreSet($this, $name, $value, $locale, $hook, $silentException);

		if($this->getDefinition()->hasProperty($name)) {
			if(!$locale)
				$locale = $this->getLocale();

			if($this->getDefinition()->property($name)->get('i18n') && $locale !== $this->getLocale()) {
				if($locale == 'all') {
					foreach($value as $locale => $v) {
						if(isset($this->data['translations'][$locale][$name]) && $v === $this->data['translations'][$locale][$name])
							continue;
						$this->data['translations'][$locale][$name] = $v;
						if($change) {
							if(!isset($this->translationschanged[$locale]))
								$this->translationschanged[$locale] = [];
							$this->translationschanged[$locale][$name] = true;
						}
					}
				}
				else {
					if(isset($this->data['translations'][$locale][$name]) && $value === $this->data['translations'][$locale][$name])
						return $this;
					$this->data['translations'][$locale][$name] = $value;
					if($change) {
						if(!isset($this->translationschanged[$locale]))
							$this->translationschanged[$locale] = [];
						$this->translationschanged[$locale][$name] = true;
					}
				}
			}
			else {
				if(isset($this->data['properties'][$name]) && $value === $this->data['properties'][$name])
					return $this;
				$this->data['properties'][$name] = $value;
				if($change) {
					if($this->getDefinition()->property($name)->get('i18n'))
						$this->translationschanged[$this->getLocale()][$name] = true;
					else
						$this->changed[$name] = true;
				}
			}
		}
		elseif($name !== 'translations' && $name !== 'properties') {
			if(is_array($value)) {
				$coll = new ManyCollection($this, $name);
				$value = $coll->setAll($value);
			}
			$this->data[$name] = $value;
		}

		return $this;
	}
1247433
public function attribute(string $name, string $value = null) : object
    {
        $this->attributes[$name] = $value;
        return $this;
    }
1271636
public function setSubject($subject)
    {
        $allowedValues = $this->getSubjectAllowableValues();
        if (!is_null($subject) && !in_array($subject, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'subject', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['subject'] = $subject;

        return $this;
    }
1215004
protected function getForeignKey($foreign)
    {
        $on = $this->wrapTable($foreign->on);

        // We need to columnize the columns that the foreign key is being defined for
        // so that it is a properly formatted list. Once we have done this, we can
        // return the foreign key SQL declaration to the calling method for use.
        $columns = $this->columnize($foreign->columns);

        $onColumns = $this->columnize((array) $foreign->references);

        return ", foreign key($columns) references $on($onColumns)";
    }
499421
final public function addForeignKey(ForeignKey $foreignKey): Column
    {
        if (array_key_exists($foreignKey->getName(), $this->foreignKeys)) {
            throw new InvalidArgumentException('Foreign key '.$foreignKey->getName().' already added.');
        }

        $this->foreignKeys[$foreignKey->getName()] = $foreignKey;

        return $this;
    }
980430
public function setReference($reference = null)
    {
        $reference === null && $reference = PaymentHelper::generateReference($this->getTransactionId());
        $this->params['reference'] = $reference;
        return $this;
    }
71482
public function setType($type = null)
    {
        $type = $this->calculateTypeValue($type);

        if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
            throw new Exception\InvalidArgumentException('Unknown type');
        }

        $this->options['type'] = $type;

        return $this;
    }
813423
public function set($property, $value = null)
	{
		if (!array_key_exists($property, $this->_tbl->getProperties()))
		{
			$property = '__' . $property;
		}
		$this->_tbl->$property = $value;
		return $this;
	}
603248
public function setEn($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->en !== $v) {
            $this->en = $v;
            $this->modifiedColumns[] = CountryPeer::EN;
        }


        return $this;
    }
1196163
public function setEmail($email, $force = false)
    {
        $email = trim($email);

        if (($this->isNew() || $force === true) && ($email === null || $email == "")) {
            throw new InvalidArgumentException("customer email is mandatory");
        }

        if (!$this->isNew() && $force === false) {
            return $this;
        }

        return parent::setEmail($email);
    }
968220
function by(Row $foreign, $ref = null) {
		// select * from $this where $this->$referencedColumn = $me->$foreignColumn
		
		if (!($rel = $foreign->getTable()->getRelation($this->getName(), $ref))) {
			return $this->onResult(null);
		}
		
		$where = array();
		foreach ($rel as $key => $ref) {
			$where["$ref="] = $foreign->$key;
		}
		return $this->find($where);
	}
1058161
public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relationship name was passed, we will pull backtraces to get the
        // name of the calling function. We will use that function name as the
        // title of this relation since that is a great convention to apply.
        if (is_null($relation)) {
            $relation = $this->getBelongsToManyCaller();
        }

        $foreignKey = $foreignKey ?: $this->getCmsReferenceKeyForRelation($relation);
        $otherKey   = $otherKey   ?: $this->getCmsReferenceKeyForRelation($relation, true);

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

        $fieldId = $this->getCmsReferenceFieldId($relation);
        if (empty($fieldId)) {
            throw new InvalidArgumentException("No 'field' id configured for relation/reference: '{$relation}'!");
        }

        // originally, it was possible to just get the parent's BelongsToMany instance, but
        // to avoid problems when saving on the relationship, we need a specialized extension
        // of the relation class for the CMS.
        //$belongsToMany = parent::belongsToMany($related, $table, $foreignKey, $otherKey);

        /** @var Model $instance */
        $instance = new $related;

        $query = $instance->newQuery();

        $belongsToMany = new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation, $fieldId);

        // add constraints
        $belongsToMany->wherePivot(config('pxlcms.relations.references.keys.field', 'from_field_id'), $fieldId);

        return $belongsToMany;
    }
620959
public function add($item)
    {
        if (is_numeric($item)) {
            $item = DataObject::get_by_id($this->dataClass, $item);
        } elseif (!($item instanceof $this->dataClass)) {
            throw new InvalidArgumentException(
                "PolymorphicHasManyList::add() expecting a $this->dataClass object, or ID value"
            );
        }

        $foreignID = $this->getForeignID();

        // Validate foreignID
        if (!$foreignID) {
            user_error(
                "PolymorphicHasManyList::add() can't be called until a foreign ID is set",
                E_USER_WARNING
            );
            return;
        }
        if (is_array($foreignID)) {
            user_error(
                "PolymorphicHasManyList::add() can't be called on a list linked to mulitple foreign IDs",
                E_USER_WARNING
            );
            return;
        }

        $foreignKey = $this->foreignKey;
        $classForeignKey = $this->classForeignKey;
        $item->$foreignKey = $foreignID;
        $item->$classForeignKey = $this->getForeignClass();

        $item->write();
    }
946945
final public function removeForeignKey(ForeignKey $foreignKey): Table
    {
        if (!$this->hasForeignKey($foreignKey::getName())) {
            throw new InvalidArgumentException('Foreign key '.$foreignKey::getName().' not exists in the table '.$this::getName());
        }

        unset($this->foreignKeys[$foreignKey::getName()]);

        return $this;
    }
717183
public function set(\Nails\Common\Factory\Locale $oLocale = null): self
    {
        $this->oLocale = $oLocale;
        return $this;
    }
577221
public function set($property, $value = null)
        {
            $this->One->set($property, $value);

            return $this;
        }