public function __clone()
{
// @TODO Support composite primary keys
- unset($this->{$this->getMapper()->model->key});
+ unset($this->{$this->getMapper()->primaryKey});
// @TODO What about associated objects?
}
// @TODO Support composite primary keys
$query = new Horde_Rdo_Query($mapper);
$query->setFields($field)
- ->addTest($mapper->model->key, '=', $this->{$mapper->model->key});
+ ->addTest($mapper->primaryKey, '=', $this->{$mapper->primaryKey});
$this->_fields[$field] = $mapper->adapter->queryOne($query);
return $this->_fields[$field];
} elseif (isset($mapper->lazyRelationships[$field])) {
break;
case Horde_Rdo::MANY_TO_MANY:
- $key = $mapper->model->key;
+ $key = $mapper->primaryKey;
$query = new Horde_Rdo_Query();
- $on = isset($rel['on']) ? $rel['on'] : $m->model->key;
+ $on = isset($rel['on']) ? $rel['on'] : $m->primaryKey;
+ var_dump($key, array($on => new Horde_Rdo_Query_Literal($on), $key => $this->$key));
$query->addRelationship($field, array('mapper' => $mapper,
'table' => $rel['through'],
'type' => Horde_Rdo::MANY_TO_MANY,
$this->inflector = new Horde_Support_Inflector();
return $this->inflector;
+ case 'primaryKey':
+ $this->primaryKey = (string)$this->tableDefinition->getPrimaryKey();
+ return $this->primaryKey;
+
case 'table':
$this->table = !empty($this->_table) ? $this->_table : $this->mapperToTable();
return $this->table;
$id = $this->adapter->insert($sql, $bindParams);
- return $this->map(array_merge(array((string)$this->tableDefinition->getPrimaryKey() => $id),
+ return $this->map(array_merge(array($this->primaryKey => $id),
$fields));
}
public function update($object, $fields = null)
{
if ($object instanceof Horde_Rdo_Base) {
- $key = (string)$this->tableDefinition->getPrimaryKey();
+ $key = $this->primaryKey;
$id = $object->$key;
$fields = iterator_to_array($object);
$sql .= ' ' . $this->adapter->quoteColumnName($field) . ' = ?,';
$bindParams[] = $value;
}
- $sql = substr($sql, 0, -1) . ' WHERE ' . (string)$this->tableDefinition->getPrimaryKey() . ' = ?';
+ $sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?';
$bindParams[] = $id;
return $this->adapter->update($sql, $bindParams);
public function delete($object)
{
if ($object instanceof Horde_Rdo_Base) {
- $key = (string)$this->tableDefinition->getPrimaryKey();
+ $key = $this->primaryKey;
$id = $object->$key;
$query = array($key => $id);
} elseif ($object instanceof Horde_Rdo_Query) {
$query = $object;
} else {
- $key = (string)$this->tableDefinition->getPrimaryKey();
+ $key = $this->primaryKey;
$query = array($key => $object);
}
if (is_numeric(key($arg))) {
// Numerically indexed arrays are assumed to be an array of
// primary keys.
- $key = (string)$this->tableDefinition->getPrimaryKey();
$query = new Horde_Rdo_Query();
$query->combineWith('OR');
foreach ($argv[0] as $id) {
- $query->addTest($key, '=', $id);
+ $query->addTest($this->primaryKey, '=', $id);
}
} else {
$query = $arg;
if (is_null($arg)) {
$query = null;
} elseif (is_scalar($arg)) {
- $query = array((string)$this->tableDefinition->getPrimaryKey() => $arg);
+ $query = array($this->primaryKey => $arg);
} else {
$query = $arg;
}