public function setValueForKey($key, $value) { if (array_key_exists($key, $this->attributeNames)) { $this->attributes[$key] = $value; } else { parent::setValueForKey($key, $value); } }
public function setValueForKey($key, $value) { if (array_key_exists($key, $this->parentNames)) { if (is_a($value, 'DatabaseObject')) { $key = $value->primaryKeyName; $value = $value->primaryKey; } } if (array_key_exists($key, $this->attributeNames)) { $this->attributes[$key] = $value; } else { if (array_key_exists($key, $this->childNames) && is_array($value)) { if (!array_key_exists($key, $this->children)) { $this->children[$key] = array(); } //Add new children foreach ($value as $child) { if (is_a($child, $this->childNames[$key]) && is_a($child, 'DatabaseObject')) { if (!array_key_exists($child->primaryKey, $this->children[$key])) { $this->children[$key][$child->primaryKey] = $child; } } } //Remove old children foreach (array_keys($this->children[$key]) as $childPrimaryKey) { if (!array_key_exists($childPrimaryKey, $value)) { unset($this->children[$key][$childPrimaryKey]); } } } else { if (array_key_exists($key, $this->peerNames) && is_array($value)) { if (!array_key_exists($key, $this->peers)) { $this->peers[$key] = array(); } //Add new peers foreach ($value as $peer) { if (is_a($peer, $this->peerNames[$key]) && is_a($peer, 'DatabaseObject')) { if (!array_key_exists($peer->primaryKey, $this->peers[$key])) { $this->peers[$key][$peer->primaryKey] = $peer; } } } //Remove old peers foreach (array_keys($this->peers[$key]) as $peerPrimaryKey) { if (!array_key_exists($peerPrimaryKey, $value)) { unset($this->peers[$key][$peerPrimaryKey]); } } } else { parent::setValueForKey($key, $value); } } } }