Bump. Anyone can help me?

On 13 дек, 12:41, Andrew Hodirevski <and...@purpled.biz> wrote:
> Hello!
> I have three models:
>
> Project
> User
> ProjectsUser
>
> The ProjectsUser table is used for HABTM relations between Project and
> User.
> This is remove() method of Project model:
>
>     function remove($project_id, $user_id)
>     {
>         /*
>          * Проверяем, относится ли выбранный проект к пользователю
>          */
> //        $data = $this->read('', $project_id);
> //
> //        if($data['User'][0]['id'] != $user_id)
> //        {
> //            return false;
> //        }
>
>         /*
>          * Если проект принадлежит пользователю, то удалить его
>          */
>         $result = $this->delete($project_id);
>
>         if(!$result)
>         {
>             return false;
>         }
>
>         return true;
>     }
>
> And remove() method of Projects controller:
>
>         function remove($project_id)
>         {
>             /*
>              * Пробуем удалить проект
>              */
>             $user_id = $this->Session->read('Auth.User.id');
>
>             $result = $this->Project->remove($project_id, $user_id);
>
>             /*
>              * Если возникли ошибки, то отправить их в буфер сообщений
> о результате операций
>              */
>             if(!$result)
>             {
>                 $this->Session->setFlash('Возникли проблемы при
> удалении проекта, попробуйте позже');
>                 $this->redirect(array(
>                     'controller' => 'projects',
>                     'action' => 'index',
>                 ));
>             }
>
>             $this->Session->setFlash('Проект успешно удален');
> //            $this->redirect(array(
> //                'controller' => 'projects',
> //                'action' => 'index',
> //            ));
>         }
>
> So, while debugging I found that Cake makes two queries for delete()
> method: deleting project by project_id from projects table and the
> next:
>
> DELETE FROM `projects_users` WHERE `projects_users`.`user_id` = 4
>
> It means that if User have two Project then after query all relations
> in projects_users table for user_id would be deleted.
> How can I fix this and why Cake deletes from projects_users by user_id
> not by project_id?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to