What does your users controller look like? Jeremy Burns Class Outfit
http://www.classoutfit.com On 20 Jul 2011, at 02:11, Diogo wrote: > The error. > > Warning (512): SQL Error: 1064: You have an error in your SQL syntax; > check the manual that corresponds to your MySQL server version for the > right syntax to use near 'index' at line 1 [CORE/cake/libs/model/ > datasources/dbo_source.php, line 684] > Code | Context > > DboSource::showQuery() - CORE/cake/libs/model/datasources/ > dbo_source.php, line 684 > DboSource::execute() - CORE/cake/libs/model/datasources/ > dbo_source.php, line 266 > DboSource::fetchAll() - CORE/cake/libs/model/datasources/ > dbo_source.php, line 410 > DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php, > line 364 > Model::call__() - CORE/cake/libs/model/model.php, line 502 > Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 50 > Role::index() - [internal], line ?? > UsersController::related_clients() - APP/controllers/ > users_controller.php, line 63 > Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204 > Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171 > Object::requestAction() - CORE/cake/libs/object.php, line 95 > include - APP/views/users/index.ctp, line 2 > View::_render() - CORE/cake/libs/view/view.php, line 731 > View::render() - CORE/cake/libs/view/view.php, line 426 > Controller::render() - CORE/cake/libs/controller/controller.php, line > 909 > Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 207 > > On 18 jul, 18:07, Diogo <dcca...@gmail.com> wrote: >> UPDATE >> >> I created a separated project to test this. Created 3 tables (users, >> projects, roles). >> >> Users: id, name >> >> Projects: id, name >> >> Roles: user_id, project_id, role >> >> Bake them all with Cake. Now I'm trying to call Role's index function >> in Users Controller, but it gives me the same error. Could this >> possibly be a bug? Or maybe I'm missing something very stupid here. :( >> >> On 17 jul, 12:25, Diogo <dcca...@gmail.com> wrote: >> >> >> >> >> >> >> >>> Hi David, thank you for answering. >> >>> Well I double checked the function name, where it has been created and >>> also if the model UserRole is being loaded up (by calling get_class). >>> Them model/controller/view were all generated by Bake, so I guess >>> everything is allright. Even when I try to call a non-custom function >>> like "index", it returns me the same error. It is, as you said, the >>> model functions aren't being loaded. I just don't know how to do it. : >>> ( >> >>> On 17 jul, 01:22, David Kullmann <kullmann.da...@gmail.com> wrote: >> >>>> Diogo: >> >>>> Notice how in your trace it shows this: >> >>>> Model::call__() - CORE/cake/libs/model/model.php, line 502 >> >>>> Looking at the Model::call__() method you can see that it is designed >>>> to handle custom function calls: >> >>>> "Handles custom method calls, like findBy<field> for DB models" >> >>>> Your model does not have the method "get_id_users" so it is falling >>>> back on Model::call__() and failing. You need to make sure you are >>>> calling the correct method, on the correct model, and that the model >>>> you are calling the method on is loaded. >> >>>> -DK >> >>>> On Jul 16, 6:03 pm, Diogo <dcca...@gmail.com> wrote: >> >>>>> I've been trying to solve this for the past 3 days and nothing has >>>>> came up. I've researched a lot and this errors usually come up when >>>>> CakePHP can't find my model or I have some name wrong in my >>>>> relationships. Well I tried looking at everything, but still couldn't >>>>> find where the error is. >>>>> I have a User model, a Project model and a UserRole model which is the >>>>> join table used by the hasMany through relationship. >> >>>>> File names: >> >>>>>> user.php project.php user_role.php >> >>>>> Models: >> >>>>> class UserRole extends AppModel { >>>>> ... >>>>> var $belongsTo = array( >>>>> 'User' => array( >>>>> 'className' => 'User', >>>>> 'foreignKey' => 'user_id', >>>>> 'conditions' => '', >>>>> 'fields' => '', >>>>> 'order' => '' >>>>> ), >>>>> 'Project' => array( >>>>> 'className' => 'Project', >>>>> 'foreignKey' => 'project_id', >>>>> 'conditions' => '', >>>>> 'fields' => '', >>>>> 'order' => '' >>>>> ) >>>>> ); >>>>> class User extends AppModel { >>>>> ... >>>>> var $hasMany = array( >>>>> ... >>>>> 'UserRole' => array( >>>>> 'className' => 'UserRole', >>>>> 'foreignKey' => 'user_id', >>>>> 'conditions' => '', >>>>> 'fields' => '', >>>>> 'order' => '' >>>>> ), >> >>>>> ); >>>>> class Project extends AppModel { >>>>> ... >>>>> var $hasMany = array( >>>>> ... >>>>> 'UserRole' => array( >>>>> 'className' => 'UserRole', >>>>> 'foreignKey' => 'project_id', >>>>> 'conditions' => '', >>>>> 'fields' => '', >>>>> 'order' => '' >>>>> ), >>>>> ); >>>>> When I try calling any method from UserRole from User, it give me the >>>>> 1064 SQL error. Any hint on where could be the problem? >> >>>>> Things I've tried so far: checked if UserRole is being loaded, and it >>>>> is. And I can call the UserRole functions from an element, they are >>>>> working fine. >> >>>>> FUNCTIONS (get_related_clients is in Users and the other is in >>>>> UserRoles): >> >>>>> function get_related_clients ($id_user, $relationship_type) { >>>>> $id_names = $this->User->UserRole->get_id_users($id_user, >>>>> $relationship_type); >>>>> ... >>>>> } >>>>> function get_id_users ($id_agency = null,$type = null) { >>>>> $params_1 = array( >>>>> 'conditions' => array('UserRole.user_id' => >>>>> $id_agency) >>>>> ); >>>>> $user_projects = $this->UserRole->find('all',$params_1); >>>>> $projects = array(); >>>>> for ($i = 0; !empty($user_projects[$i]); $i++) { >>>>> $projects[] = >>>>> $user_projects[$i]['UserRole']['project_id']; >>>>> } >>>>> $clients = array(); >>>>> foreach ($projects as $project) { //pega o id de todos os >>>>> usuarios >>>>> que sao clientes da lista de projetos anteriores >>>>> $params_2 = array( >>>>> 'conditions' => >>>>> array('UserRole.project_id' => $project, >>>>> 'UserRole.role' => $type) >>>>> ); >>>>> $client_project = >>>>> $this->UserRole->find('first',$params_2); >>>>> if ($id_agency != >>>>> $client_project['UserRole']['user_id']) >>>>> { $clients[] = $client_project['UserRole']['user_id']; } // voce nao >>>>> pode ser cliente de voce mesmo >>>>> } >>>>> return $clients; >>>>> } >> >>>>> ERROR: >> >>>>> Warning (512): SQL Error: 1064: You have an error in your SQL >>>>> syntax; check the manual that corresponds to your MySQL server version >>>>> for the right syntax to use near 'get_id_users' at line 1 >>>>> DboSource::showQuery() - CORE/cake/libs/model/datasources/ >>>>> dbo_source.php, line 684 >>>>> DboSource::execute() - CORE/cake/libs/model/datasources/ >>>>> dbo_source.php, line 266 >>>>> DboSource::fetchAll() - CORE/cake/libs/model/datasources/ >>>>> dbo_source.php, line 410 >>>>> DboSource::query() - CORE/cake/libs/model/datasources/ >>>>> dbo_source.php, line 364 >>>>> Model::call__() - CORE/cake/libs/model/model.php, line 502 >>>>> Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, >>>>> line 50 >>>>> UserRole::get_id_users() - [internal], line ?? >>>>> UsersController::get_related_clients() - APP/controllers/ >>>>> users_controller.php, line 71 >>>>> Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204 >>>>> Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171 >>>>> Object::requestAction() - CORE/cake/libs/object.php, line 95 >>>>> include - APP/views/elements/client_list.ctp, line 2 >>>>> View::_render() - CORE/cake/libs/view/view.php, line 731 >>>>> View::element() - CORE/cake/libs/view/view.php, line 392 >>>>> include - APP/views/projects/index.ctp, line 45 >>>>> View::_render() - CORE/cake/libs/view/view.php, line 731 > > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and help > others with their CakePHP related questions. > > > 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 -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. 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