Re: Incorrect behavior of delete() method
Project: var $hasAndBelongsToMany = array( 'User' => array( 'className' => 'User', 'joinTable' => 'projects_users', 'foreignKey' => 'project_id', 'associationForeignKey' => 'user_id', 'with' => 'ProjectsUser', 'unique' => true, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' ) ); User: var $hasAndBelongsToMany = array( 'Project' => array( 'className' => 'Project', 'joinTable' => 'projects_users', 'foreignKey' => 'user_id', 'associationForeignKey' => 'project_id', 'with' => 'ProjectsUser', 'unique' => true, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' ) ); ProjectsUser var $belongsTo = array( 'User' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Project' => array( 'className' => 'Project', 'foreignKey' => 'project_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'ProjectsUsersRole' => array( 'className' => 'ProjectsUsersRole', 'foreignKey' => 'projects_users_role_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); On 15 дек, 20:04, cricket wrote: > 2010/12/15 Andrew Hodirevski : > > > > > > > > > > > Bump. Anyone can help me? > > > On 13 дек, 12:41, Andrew Hodirevski 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); > > >> /* > >> * Если возникли ошиб
Re: Incorrect behavior of delete() method
Bump. Anyone can help me? On 13 дек, 12:41, Andrew Hodirevski 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
Re: Incorrect behavior of delete() method
Bump. Anyone can help me? On 13 дек, 12:41, Andrew Hodirevski 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
Incorrect behavior of delete() method
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
Internationalization in Cake - not works for me
What am I doing wrong? I've got the next part of View: __('Ваш логин', true), After that I've generated using cake 'cake i18n extract' neccessary path and default.pot, which I copied to app/locale/eng/LC_MESSAGES/ default.po and edited with PoEdit. The part of default.po for the previous string is: msgid "Ваш логин" msgstr "Your login" And: "Plural-Forms: nplurals=2; plural=(n != 1);\n" The Debug level is 2, so I have no caching. So, what the problem is? 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
Re: Containable Behavior, conditions and empty array
I saw this thread before posting. In thread which you posted there no any solution than foreach/if. You can see that I wrote that 'how can I exclude this empty array (whole [2] array I mean) without using foreach/if blocks? I know that using bindModel will do all as well but this is not for my question ;) So, how?' On 9 дек, 17:07, "j.blotus" wrote: > Please see > > http://groups.google.com/group/cake-php/browse_thread/thread/f649c3b2... > > On Dec 9, 9:44 am, Andrew Hodirevski wrote: > > > > > > > > > Hello! > > I have the next question. > > > There is part of code: > > > $result = $this->find('all', array( > > 'contain' => array( > > 'User' => array( > > 'fields' => 'id', > > 'conditions' => array( > > 'id' => $user_id > > ) > > ) > > ), > > 'fields' => 'url' > > )); > > > This find() called in method of Project model class and I want to > > retrieve just projects where User.id equal some user id passed to my > > method. > > User HABTM Project and Project HABTM User. > > > But after executing I have the next: > > > app/views/projects/index.ctp (line 1) > > > Array > > ( > > [0] => Array > > ( > > [Project] => Array > > ( > > [url] =>http://purpled.biz > > [id] => 1 > > ) > > > [User] => Array > > ( > > [0] => Array > > ( > > [id] => 4 > > [ProjectsUser] => Array > > ( > > [user_id] => 4 > > [project_id] => 1 > > [projects_users_role_id] => 0 > > ) > > > ) > > > ) > > > ) > > > [1] => Array > > ( > > [Project] => Array > > ( > > [url] =>http://google.com > > [id] => 2 > > ) > > > [User] => Array > > ( > > [0] => Array > > ( > > [id] => 4 > > [ProjectsUser] => Array > > ( > > [user_id] => 4 > > [project_id] => 2 > > [projects_users_role_id] => 0 > > ) > > > ) > > > ) > > > ) > > > [2] => Array > > ( > > [Project] => Array > > ( > > [url] =>http://test.com > > [id] => 3 > > ) > > > [User] => Array > > ( > > ) > > > ) > > > ) > > > As you see there is the last array with empty [User] array, so how can > > I exclude this empty array (whole [2] array I mean) without using > > foreach/if blocks? I know that using bindModel will do all as well but > > this is not for my question ;) So, how? 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
Containable Behavior, conditions and empty array
Hello! I have the next question. There is part of code: $result = $this->find('all', array( 'contain' => array( 'User' => array( 'fields' => 'id', 'conditions' => array( 'id' => $user_id ) ) ), 'fields' => 'url' )); This find() called in method of Project model class and I want to retrieve just projects where User.id equal some user id passed to my method. User HABTM Project and Project HABTM User. But after executing I have the next: app/views/projects/index.ctp (line 1) Array ( [0] => Array ( [Project] => Array ( [url] => http://purpled.biz [id] => 1 ) [User] => Array ( [0] => Array ( [id] => 4 [ProjectsUser] => Array ( [user_id] => 4 [project_id] => 1 [projects_users_role_id] => 0 ) ) ) ) [1] => Array ( [Project] => Array ( [url] => http://google.com [id] => 2 ) [User] => Array ( [0] => Array ( [id] => 4 [ProjectsUser] => Array ( [user_id] => 4 [project_id] => 2 [projects_users_role_id] => 0 ) ) ) ) [2] => Array ( [Project] => Array ( [url] => http://test.com [id] => 3 ) [User] => Array ( ) ) ) As you see there is the last array with empty [User] array, so how can I exclude this empty array (whole [2] array I mean) without using foreach/if blocks? I know that using bindModel will do all as well but this is not for my question ;) So, how? 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
Re: Some questions about HABTM relations and join tables.
You mean bindModel() calls? On 9 дек, 12:00, Almudena Garcia wrote: > Good day, > > Isn't it simple if you paste here your code? > Anyway, I don't see in your cake query any join... > What are you trying to do? > > Regards. > > 2010/12/9 Andrew Hodirevski > > > > > > > > > Good day! > > So, I have the next tables: > > > projects > > users > > projects_users > > > Project hasAndBelongsToMany User > > User hasAndBelongsToMany Project > > ProjectsUser belongsTo User > > ProjectsUser belongsTo Project > > > Here is code all of models: > >https://gist.github.com/734531 > > > So, when I am trying to do the next query: > >https://gist.github.com/734540 > > > Cake generates the next SQL queries: > >https://gist.github.com/734533 > > > You can see that queries between User and Project are separated but > > relations are set in models. Also you can see that belongsTo relations > > between ProjectsStatus and ProjectsError to Project model are executed > > successfully as joining this tables in the first query. The commented > > line in code show what I want. > > > So, the question is: > > Why Cake not automatically joins my HABTM relations between Project > > and User and how to do it? It I use the 'joins' => array() all is > > work, but I want it be done automatically. > > > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 > om>For more options, visit this group at > >http://groups.google.com/group/cake-php?hl=en 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
Some questions about HABTM relations and join tables.
Good day! So, I have the next tables: projects users projects_users Project hasAndBelongsToMany User User hasAndBelongsToMany Project ProjectsUser belongsTo User ProjectsUser belongsTo Project Here is code all of models: https://gist.github.com/734531 So, when I am trying to do the next query: https://gist.github.com/734540 Cake generates the next SQL queries: https://gist.github.com/734533 You can see that queries between User and Project are separated but relations are set in models. Also you can see that belongsTo relations between ProjectsStatus and ProjectsError to Project model are executed successfully as joining this tables in the first query. The commented line in code show what I want. So, the question is: Why Cake not automatically joins my HABTM relations between Project and User and how to do it? It I use the 'joins' => array() all is work, but I want it be done automatically. 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
Re: Call to undefined method Shell::getAssociated()
Huh, you are right, it was overrided. Btw can I use separate usermodel Shells and not to have conflict with core Shell model? On 7 дек, 23:53, AD7six wrote: > in the absence of any useful information I'd say you've created a model > named Shell - Shell is a core class, so should be considered a reserved > name. > > hth, > > AD 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
Call to undefined method Shell::getAssociated()
Hello! I got a subj error when I creating some models. I use the last cake version and windows 7. So, what the problem is and how can I fix it? 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
Why the error "Class 'ErrorHandler' not found" throws?
Hello! I am using the latest versions of CakePHP and SimpleTest but when I start unittests the next error throws: Fatal error: Class 'ErrorHandler' not found in Z:\home\prodvigator\www \cake\libs\object.php on line 201 So, why? 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