Skip to content

Commit 21bef7d

Browse files
committed
DELETE forms/:id - Return JSON and delete related objects #1
Returns an empty array or the form just deleted (if it exists) Deleting a form will now delete its attributes and groups too.
1 parent 2419e44 commit 21bef7d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

application/classes/Controller/Api/Forms.php

+3
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ public function action_delete_index()
179179
{
180180
$form_id = $this->request->param('id', 0);
181181
$form = ORM::factory('Form', $form_id);
182+
$this->_response_payload = array();
182183
if ( $form->loaded() )
183184
{
185+
// Return the form we just deleted (provides some confirmation)
186+
$this->_response_payload = $this->form($form);
184187
$form->delete();
185188
}
186189
}

application/classes/Model/Form.php

+23
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,27 @@ public function rules()
7575
// Insert/Update Timestamps
7676
protected $_created_column = array('column' => 'created', 'format' => TRUE);
7777
protected $_updated_column = array('column' => 'updated', 'format' => 'Y-m-d H:i:s');
78+
79+
/**
80+
* Deletes a single record while ignoring relationships.
81+
* Extend ORM::delete() to cascade delete assoc. objects
82+
*
83+
* @chainable
84+
* @return ORM
85+
*/
86+
public function delete()
87+
{
88+
// Delete associated objects
89+
if ($this->form_attributes->loaded())
90+
{
91+
$this->form_attributes->delete();
92+
}
93+
94+
if ($this->form_groups->loaded())
95+
{
96+
$this->form_groups->delete();
97+
}
98+
99+
parent::delete();
100+
}
78101
}

0 commit comments

Comments
 (0)