04-13-2011, 09:07 PM
[eluser]johnmerlino[/eluser]
Hey all,
I looked at this documentation:
http://datamapper.wanwizard.eu/pages/delete.html
It says you can delete relationships with datamapper.
I have a categories table and categories_related_categories table.
categories table has primary key id and categories_related_categories table looks like this:
In the example above, there's a category with id of 122 and a category with id of 25. When I delete relationship I expect this record to disappear since there is no more relationship between the two records. But after using delete, the record remains in the categories_related_categories table. This is what I have:
When the user selects none from dropdown and returned_controller is then equal to none, this line executes:
I know for a fact that $category->related_category->get() returns the right relationship because when I inspect it with var_dump, I see that it's the right category. So basically I am deleting the category associated with the current category. Yet when this function runs during update call, I look in database and the relationship is not deleted from the categories_related_categories table.
I also took a look at the "delete advanced relationships" section of that link I post. It appears to use a $related_ids variable, which is not defined anywhere and of course throws a php exception. But I don't believe I need that advanced section anyway because I am just trying to delete a category that is a parent of another category.
Thanks for response.
Hey all,
I looked at this documentation:
http://datamapper.wanwizard.eu/pages/delete.html
It says you can delete relationships with datamapper.
I have a categories table and categories_related_categories table.
categories table has primary key id and categories_related_categories table looks like this:
Code:
id category_id category_related_id
1 122 25
In the example above, there's a category with id of 122 and a category with id of 25. When I delete relationship I expect this record to disappear since there is no more relationship between the two records. But after using delete, the record remains in the categories_related_categories table. This is what I have:
Code:
public function update(){
$vanity_url = new VanityUrl();
$vanity_url->where('user_id',$this->current_user()->id)->get();
$category = new Category();
$category = $category->where('id',$this->uri->segment(4))->get();
$category->controller = $this->input->post('controller');
$category->enable_comments = $this->input->post('approved');
$returned_controller = $this->input->post('parent_controller');
$parent_category = new Category();
$parent_category->where('controller',$returned_controller)->get();
$zones = $this->input->post('zones');
$zone = new Zone();
$zone->where_in('name', $zones)->get();
if($returned_controller == "none"){
$category->delete($category->related_category->get());
if($category->save($zone->all)){
redirect("blogs/$vanity_url->url/categories");
}
}
elseif($category->save( array($zone->all, 'related_category' => $parent_category))){
$this->session->set_flashdata('flash_message', 'The category has been successfully updated.');
redirect("blogs/$vanity_url->url/categories");
}
else {
$this->session->set_flashdata('flash_message', 'An error has occurred. Please try updating the category again.');
redirect("blogs/$vanity_url->url/categories/{$category->id}/edit");
}
}
When the user selects none from dropdown and returned_controller is then equal to none, this line executes:
Code:
$category->delete($category->related_category->get())
I also took a look at the "delete advanced relationships" section of that link I post. It appears to use a $related_ids variable, which is not defined anywhere and of course throws a php exception. But I don't believe I need that advanced section anyway because I am just trying to delete a category that is a parent of another category.
Thanks for response.