lithium\data\model\Relationship::foreignKey()

public method

Build foreign keys from primary keys array.

Parameters

  • $primaryKey An

    array where keys are primary keys and values are the associated values of primary keys.

Returns

array

An array where keys are foreign keys and values are the associated values of foreign keys.

Source

	public function foreignKey($primaryKey) {
		$result = [];
		$entity = $this->_classes['entity'];
		$keys = ($this->type() === 'belongsTo') ? array_flip($this->key()) : $this->key();
		$primaryKey = ($primaryKey instanceof $entity) ? $primaryKey->to('array') : $primaryKey;

		foreach ($keys as $key => $foreignKey) {
			$result[$foreignKey] = $primaryKey[$key];
		}
		return $result;
	}