diff --git a/lib/Doctrine/Resource/Collection.php b/lib/Doctrine/Resource/Collection.php index 215393a4f..7db93016e 100644 --- a/lib/Doctrine/Resource/Collection.php +++ b/lib/Doctrine/Resource/Collection.php @@ -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(); + } + } } diff --git a/lib/Doctrine/Resource/Record.php b/lib/Doctrine/Resource/Record.php index 4abe18305..b422e4177 100644 --- a/lib/Doctrine/Resource/Record.php +++ b/lib/Doctrine/Resource/Record.php @@ -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; diff --git a/lib/Doctrine/Resource/Server.php b/lib/Doctrine/Resource/Server.php index b80391a0d..999b8d881 100644 --- a/lib/Doctrine/Resource/Server.php +++ b/lib/Doctrine/Resource/Server.php @@ -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'); diff --git a/playground/index.php b/playground/index.php index 23bdf5a5e..9f5ea2af6 100644 --- a/playground/index.php +++ b/playground/index.php @@ -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()); } \ No newline at end of file