35,9 → 35,15 |
* the <code>Table</code>, if specified (keys are property names, |
* values are column names, or both if the key is numeric). |
* |
* NOTE: It should not be necessary to include the |
* <code>persistentId</code> property value here. If an object |
* is not in the database, it should be assigned an ID |
* automatically when saved; if it is in the database, |
* you already have its ID as you searched by it. |
* |
* @type array |
*/ |
protected $_persistentProperties = array('id'); |
protected $_persistentProperties = array(); |
|
/** |
* Creates a new model object |
114,7 → 120,7 |
} |
|
/** |
* Finds the record for the model object in a database, fills |
* Finds the record for the model object in the table, fills |
* the object with missing data, and returns the result. |
* |
* @see Table::find(Model) |
124,8 → 130,7 |
*/ |
public function find () |
{ |
$result = $this->persistentTable->find( |
$this->{$this->_persistentId}); |
$result = $this->persistentTable->find($this->{$this->_persistentId}); |
if ($result) |
{ |
return $this->map($result); |
135,7 → 140,7 |
} |
|
/** |
* Saves a model object in the <code>Table</code> |
* Saves the model object in the table |
* |
* @param array $propertyNames = null |
* Names of the properties whose values should be saved |
147,14 → 152,51 |
*/ |
public function save (array $propertyNames = null) |
{ |
return $this->persistentTable->updateOrInsert( |
$this->getPropertyArray($propertyNames), array( |
$this->persistentTable->id => $this->{$this->_persistentId} |
$table = $this->persistentTable; |
$idPropertyName = $this->_persistentId; |
|
$result = $table->updateOrInsert( |
$this->getPropertyArray($propertyNames), |
array( |
$table->id => $this->$idPropertyName |
) |
); |
|
if ($result && ($lastInsertId = $table->lastInsertId)) |
{ |
$this->$idPropertyName = $lastInsertId; |
} |
|
return $result; |
} |
|
/** |
* Inserts the model object into the table |
* |
* @param array $propertyNames = null |
* Names of the properties whose values should be insert |
* in the database. The default is to insert the values |
* of all persistent properties. |
* @return boolean |
* @see Model::getPropertyArray() |
* @see Table::insert() |
*/ |
public function insert (array $propertyNames = null) |
{ |
$table = $this->persistentTable; |
$idPropertyName = $this->_persistentId; |
|
$result = $table->insert($this->getPropertyArray($propertyNames)); |
|
if ($result && ($lastInsertId = $table->lastInsertId)) |
{ |
$this->$idPropertyName = $lastInsertId; |
} |
|
return $result; |
} |
|
/** |
* Deletes a model object from the <code>Table</code> |
* |
* @return bool |