Commit eca4f7a1 authored by Jonathan.Wage's avatar Jonathan.Wage

Added delete functionality to records.

parent 6d6f6c75
...@@ -104,4 +104,11 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C ...@@ -104,4 +104,11 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C
$record->save(); $record->save();
} }
} }
public function delete()
{
foreach ($this as $record) {
$record->delete();
}
}
} }
...@@ -169,6 +169,7 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count ...@@ -169,6 +169,7 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$request->set('type', 'save'); $request->set('type', 'save');
$request->set('model', $this->getModel()); $request->set('model', $this->getModel());
$request->set('data', $this->getChanges()); $request->set('data', $this->getChanges());
$request->set('identifier', $this->identifier());
$response = $request->execute(); $response = $request->execute();
...@@ -177,6 +178,19 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count ...@@ -177,6 +178,19 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$this->_data = $request->hydrate(array($array), $this->_model)->getFirst()->_data; $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() public function getModel()
{ {
return $this->_model; return $this->_model;
......
...@@ -48,26 +48,19 @@ class Doctrine_Resource_Server extends Doctrine_Resource ...@@ -48,26 +48,19 @@ class Doctrine_Resource_Server extends Doctrine_Resource
{ {
$model = $request->get('model'); $model = $request->get('model');
$data = $request->get('data'); $data = $request->get('data');
$identifier = $request->get('identifier');
$table = Doctrine_Manager::getInstance()->getTable($model); $table = Doctrine_Manager::getInstance()->getTable($model);
$identifier = $table->getIdentifier();
if (!is_array($identifier)) {
$identifier = array($identifier);
}
$existing = true; $existing = true;
$pks = array(); foreach ($identifier as $key => $value) {
foreach ($identifier as $name) { if (!$value) {
if (isset($data[$name]) && $data[$name]) {
$pks[$name] = $data[$name];
} else {
$existing = false; $existing = false;
} }
} }
if ($existing) { if ($existing) {
$record = $table->find($pks); $record = $table->find($identifier);
} else { } else {
$record = new $model(); $record = new $model();
} }
...@@ -78,6 +71,18 @@ class Doctrine_Resource_Server extends Doctrine_Resource ...@@ -78,6 +71,18 @@ class Doctrine_Resource_Server extends Doctrine_Resource
return $record->toArray(true, true); 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) public function executeQuery($request)
{ {
$dql = $request->get('dql'); $dql = $request->get('dql');
......
...@@ -19,7 +19,10 @@ if ($action == 'server') { ...@@ -19,7 +19,10 @@ if ($action == 'server') {
$client = Doctrine_Resource_Client::getInstance($config); $client = Doctrine_Resource_Client::getInstance($config);
$user = new User(); $user = $client->find('User', 4);
$user->Phonenumber->add()->phonenumber = '555-5555';
$user->name = 'jonnwage'; $user->name = 'jonnwage';
$user->save(); $user->save();
print_r($user->toArray());
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment