Welcome Guest, Not a member yet? Register   Sign In
unable to delete relationship with datamapper using delete()
#3

[eluser]johnmerlino[/eluser]
Thanks for response. Your code was pretty similar to what I had and so it didn't do anything different. However, I did add the check_last_query function and it returned this:

Code:
DELETE FROM `categories_related_categories`
WHERE `related_category_id` = 122
AND `category_id` = 25

This is strange because the related_category has an id of 25 and the category has an id of 122. So this statement has it backwards.

This is the category model:

Code:
public $has_many = array(
            'related_category' => array(
                'class' => 'category',
                'other_field' => 'category',
               // 'reciprocal' => TRUE
            ),
            'category' => array(
                'other_field' => 'related_category',
            ),
            'post',
             'zone' => array(            
                        'class' => 'zone',    
                        'other_field' => 'category',    
                        'join_self_as' => 'category',    
                        'join_other_as' => 'zone',    
                        'join_table' => 'categories_zones',    
                )
         );

Not sure what I am doing wrong.

Now if I reverse it:

Code:
if($returned_controller == "none"){
                $category->related_category->get();
                $category->related_category->delete($category->all);  
               //    $category->delete($category->related_category->get());
                 if($category->save($zone->all)){
                    redirect("blogs/$vanity_url->url/categories");
                }
            }

it works fine. But while this works, it's weird because category is the child (e.g. 122) and related should be parent (25), since the uri segment grabs 122 and I want to find 122's parent, which is 25. Yet it seems like I have to invoke delete on the parent, not the child, as shown above. It's a little unintuitive.

And when I want to delete multiple relationships associated with a category, I have to do this:

Code:
if($category->related_category->delete($category) && $category->delete($zones->all) && $category->delete()){
                    $this->session->set_flashdata('flash_message', 'The category has been successfully deleted.');
                    redirect("blogs/{$vanity_url->url}/categories");
                }

when I would prefer to do this:

Code:
if($category->delete($category->related_category,$zones->all){}

Thanks for response.


Messages In This Thread
unable to delete relationship with datamapper using delete() - by El Forum - 04-14-2011, 04:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB