1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Added delete functionality to records.

This commit is contained in:
Jonathan.Wage 2007-09-24 21:46:05 +00:00
parent 6d6f6c7598
commit eca4f7a121
4 changed files with 41 additions and 12 deletions

View File

@ -104,4 +104,11 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C
$record->save();
}
}
public function delete()
{
foreach ($this as $record) {
$record->delete();
}
}
}

View File

@ -169,6 +169,7 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$request->set('type', 'save');
$request->set('model', $this->getModel());
$request->set('data', $this->getChanges());
$request->set('identifier', $this->identifier());
$response = $request->execute();
@ -177,6 +178,19 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$this->_data = $request->hydrate(array($array), $this->_model)->getFirst()->_data;
}
public function delete()
{
$format = $this->getConfig('format');
$request = new Doctrine_Resource_Request();
$request->set('format', $format);
$request->set('type', 'delete');
$request->set('model', $this->getModel());
$request->set('identifier', $this->identifier());
$response = $request->execute();
}
public function getModel()
{
return $this->_model;

View File

@ -48,26 +48,19 @@ class Doctrine_Resource_Server extends Doctrine_Resource
{
$model = $request->get('model');
$data = $request->get('data');
$identifier = $request->get('identifier');
$table = Doctrine_Manager::getInstance()->getTable($model);
$identifier = $table->getIdentifier();
if (!is_array($identifier)) {
$identifier = array($identifier);
}
$existing = true;
$pks = array();
foreach ($identifier as $name) {
if (isset($data[$name]) && $data[$name]) {
$pks[$name] = $data[$name];
} else {
foreach ($identifier as $key => $value) {
if (!$value) {
$existing = false;
}
}
if ($existing) {
$record = $table->find($pks);
$record = $table->find($identifier);
} else {
$record = new $model();
}
@ -78,6 +71,18 @@ class Doctrine_Resource_Server extends Doctrine_Resource
return $record->toArray(true, true);
}
public function executeDelete($request)
{
$model = $request->get('model');
$identifier = $request->get('identifier');
$table = Doctrine_Manager::getInstance()->getTable($model);
$record = $table->find($identifier);
$record->delete();
}
public function executeQuery($request)
{
$dql = $request->get('dql');

View File

@ -19,7 +19,10 @@ if ($action == 'server') {
$client = Doctrine_Resource_Client::getInstance($config);
$user = new User();
$user = $client->find('User', 4);
$user->Phonenumber->add()->phonenumber = '555-5555';
$user->name = 'jonnwage';
$user->save();
print_r($user->toArray());
}