/** * {@inheritdoc} * * Overloaded to support relationships. * */ public function initialize(array $properties = null) { $hasOne = []; $hasMany = []; if (null !== $properties) { foreach ($properties as $key => $value) { if (true === $this->isHasOne($key)) { // Load hasOne relationship. $hasOne[$key] = $this->getStore()->loadProxyModel($value['type'], $value['id']); continue; } } } foreach ($this->getMetadata()->getRelationships() as $key => $relMeta) { if (true === $relMeta->isOne()) { continue; } if (true === $relMeta->isInverse) { $hasMany[$key] = $this->getStore()->createInverseCollection($relMeta, $this); } else { $references = !isset($properties[$key]) ? [] : $properties[$key]; $hasMany[$key] = $this->getStore()->createCollection($relMeta, $references); } } $this->hasOneRelationships = null === $this->hasOneRelationships ? new Relationships\HasOne($hasOne) : $this->hasOneRelationships->replace($hasOne); $this->hasManyRelationships = null === $this->hasManyRelationships ? new Relationships\HasMany($hasMany) : $this->hasManyRelationships->replace($hasMany); return parent::initialize($properties); }