for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* components
*
* @author Wolfy-J
*/
namespace Spiral\ORM\Entities\Relations\Traits;
use Spiral\ORM\ContextualCommandInterface;
use Spiral\ORM\RecordInterface;
* Looks for key values in command context AND in outer field if possible.
trait LookupTrait
{
* @param int $key
* @param RecordInterface $record
* @param ContextualCommandInterface $command
* @return mixed|null
protected function lookupKey(
int $key,
RecordInterface $record,
ContextualCommandInterface $command = null
) {
$key = $this->key($key);
if (!empty($command)) {
$context = $command->getContext();
if (!empty($context[$key])) {
//Key value found in a context
return $context[$key];
}
if ($key == $this->primaryColumnOf($record)) {
return $command->primaryKey();
//Fallback lookup in a record
return $record->getField($key, null);
* Key name.
* @return string
abstract protected function key(int $key): string;
* Get primary key column
abstract protected function primaryColumnOf(RecordInterface $record): string;