Controller confusion
Hi list Once again, I find myself stuck. I have three tables - users - managers - projects. The users table has fields defined for users real name (user.realname) and an id (user.id), the managers table has fields defined for the user id (manager.user_id) and a projects table which has fields defined for project id (project.id) and managers id (project.manager_id). These arent the only fields but it makes it a little easier. I've defined my models to associate the three tables // models/manager.php ?php class Manager extends AppModel { var $name = 'Manager'; var $hasone = array('User' = array( 'className' = 'User', 'conditions' = '', 'order' = '', 'dependent' = true, 'foreignKey' = 'user_id' ) ); } ? and // models/project.php ?php class Project extends AppModel { var $name = 'Project'; var $useTable = 'projects'; var $belongsTo = array( 'Manager' = array('className' = 'Manager', 'foreignKey' = 'manager_id', 'conditions' = '', 'fields' = '', 'order' = '' ); } ? What I want to be able to do is in my projects view is to see the fullname of the manager. I can get the managers user ID by adding the following within my projects controller... $l = $this-Job-Manager-find('all', array('fields' = array('Manager.id', 'Manager.user_id'))); $result = Set::combine($l, {n}.Manager.id, {n}.Manager.user_id); $this-set('managers', $result); and in my projects view, I can use $managers to create a select list. What I cant seem to work out is how to see the managers fullname instead of his/her userid. I believe this is because its not inside my projects model but I'm really not sure. I hope that is enough information. Any help would be gratefully received. Thanks JudoUK --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Controller confusion
I think your problem is that you're asking cake to just bring you the id's: array('fields' =array('Manager.id http://manager.id/', 'Manager.user_id') should be: array('fields' =array('Manager.id http://manager.id/', 'Manager.user_id', 'User.realname') On Jan 31, 2008 8:09 PM, judouk [EMAIL PROTECTED] wrote: Hi list Once again, I find myself stuck. I have three tables - users - managers - projects. The users table has fields defined for users real name (user.realname) and an id (user.id), the managers table has fields defined for the user id (manager.user_id) and a projects table which has fields defined for project id (project.id) and managers id (project.manager_id). These arent the only fields but it makes it a little easier. I've defined my models to associate the three tables // models/manager.php ?php class Manager extends AppModel { var $name = 'Manager'; var $hasone = array('User' = array( 'className' = 'User', 'conditions' = '', 'order' = '', 'dependent' = true, 'foreignKey' = 'user_id' ) ); } ? and // models/project.php ?php class Project extends AppModel { var $name = 'Project'; var $useTable = 'projects'; var $belongsTo = array( 'Manager' = array('className' = 'Manager', 'foreignKey' = 'manager_id', 'conditions' = '', 'fields' = '', 'order' = '' ); } ? What I want to be able to do is in my projects view is to see the fullname of the manager. I can get the managers user ID by adding the following within my projects controller... $l = $this-Job-Manager-find('all', array('fields' = array('Manager.id', 'Manager.user_id'))); $result = Set::combine($l, {n}.Manager.id, {n}.Manager.user_id); $this-set('managers', $result); and in my projects view, I can use $managers to create a select list. What I cant seem to work out is how to see the managers fullname instead of his/her userid. I believe this is because its not inside my projects model but I'm really not sure. I hope that is enough information. Any help would be gratefully received. Thanks JudoUK -- Matias Lespiau http://www.gignus.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Controller confusion
On 31 Jan, 23:49, Matias Lespiau [EMAIL PROTECTED] wrote: I think your problem is that you're asking cake to just bring you the id's: Thanks I've tried that I now have $l = $this-Job-Manager-find('all', array('fields' = array('Manager.id', 'Manager.user_id', 'User.first_name', 'User.surname'))); $result = Set::combine($l, {n}.Manager.id, {n}.Manager.user_id); $this-set('managers', $result); but now I get the error; Query: SELECT `Manager`.`id`, `Manager`.`user_id`, `User`.`first_name`, `User`.`surname` FROM `managers` AS `Manager` WHERE 1 = 1 Warning (512): SQL Error: 1109: Unknown table 'User' in field list [CORE/cake/libs/model/datasources/dbo_source.php, line 440] I suspect this is because the two tables aren't linked in that way. Not sureits getting late at night so may not be thinking about this the right way either! (which probably isnt helping) J --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Controller confusion
I think case matters and you have a typo when setting the asociation (you wrote $hasone and it's $hasOne ). Also try setting the recursion level to something 0 before calling find: $this-Job-Manager-recursive = 1; $l = $this-Job-Manager-find('all', array('fields' = array('Manager.id http://manager.id/', 'Manager.user_id', 'User.first_name ', 'User.surname'))); $result = Set::combine($l, {n}.Manager.id, {n}.Manager.user_id); $this-set('managers', $result); Good luck, I hope that works! On Jan 31, 2008 10:14 PM, judouk [EMAIL PROTECTED] wrote: On 31 Jan, 23:49, Matias Lespiau [EMAIL PROTECTED] wrote: I think your problem is that you're asking cake to just bring you the id's: Thanks I've tried that I now have $l = $this-Job-Manager-find('all', array('fields' = array('Manager.id', 'Manager.user_id', 'User.first_name', 'User.surname'))); $result = Set::combine($l, {n}.Manager.id, {n}.Manager.user_id); $this-set('managers', $result); but now I get the error; Query: SELECT `Manager`.`id`, `Manager`.`user_id`, `User`.`first_name`, `User`.`surname` FROM `managers` AS `Manager` WHERE 1 = 1 Warning (512): SQL Error: 1109: Unknown table 'User' in field list [CORE/cake/libs/model/datasources/dbo_source.php, line 440] I suspect this is because the two tables aren't linked in that way. Not sureits getting late at night so may not be thinking about this the right way either! (which probably isnt helping) J -- Matias Lespiau http://www.gignus.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---