setPrimaryKey() публичный Метод

public setPrimaryKey ( array $primaryKey )
$primaryKey array
Пример #1
0
 public function parseMetadata($class, &$fileDependencies)
 {
     $this->reflection = new ClassType($class);
     $this->metadata = new EntityMetadata($class);
     $this->primaryKey = [];
     $this->loadProperties($fileDependencies);
     $this->loadGettersSetters();
     // makes id property virtual on entities with composite primary key
     if ($this->primaryKey && $this->metadata->hasProperty('id')) {
         $this->metadata->getProperty('id')->isVirtual = TRUE;
     }
     $fileDependencies = array_unique($fileDependencies);
     $this->metadata->setPrimaryKey($this->primaryKey ?: ['id']);
     return $this->metadata;
 }
Пример #2
0
 protected function initPrimaryKey()
 {
     $primaryKey = array_values(array_filter(array_map(function (PropertyMetadata $metadata) {
         return $metadata->isPrimary && !$metadata->isVirtual ? $metadata->name : null;
     }, $this->metadata->getProperties())));
     if (empty($primaryKey)) {
         throw new InvalidStateException("Entity {$this->reflection->name} does not have defined any primary key.");
     } elseif (!$this->metadata->hasProperty('id') || !$this->metadata->getProperty('id')->isPrimary) {
         throw new InvalidStateException("Entity {$this->reflection->name} has to have defined \$id property as {primary} or {primary-proxy}.");
     }
     $this->metadata->setPrimaryKey($primaryKey);
 }