Re: How to get information in a mysql table from a different controller.
I'm not sure if you're trying to use the Post -> Period association or the User -> Period association. As Jeremy says, If your periods table has a foreign key into the posts table, the foreign key should be period_id. You should then have the association set-up in your Post model. Bake can setup the associations easily if you follow the conventions for table naming and ids. If you're trying to get all the Periods with a specific user id, you probably wanna include the Periods table in your PostsController : public $uses = array('Post' , 'Period') ; then you can get it out of the Period table quite easily : $userPeriods = $this -> Period -> find('all' , array('conditions' => array( 'Period.user_id' => ' your auth user id' ))) ; On Nov 23, 5:46 am, Jeremy Burns | Class Outfit wrote: > Does your posts table have a field called period or is it period_id? If it's > period, that's bad database design. You should change it to period_id so that > it relates to the id column in the periods table. Then your problem is an > easy one to overcome using table associations. > > Jeremy Burns > Class Outfit > > http://www.classoutfit.com > > On 22 Nov 2011, at 18:08, GG wrote: > > > I have two tables, a posts table, and a periods table. > > > The posts table has a user_id, title, body, period. > > > The periods table has a user_id, title, period. > > > I can easily get the information from the posts table in my > > PostsController.php: > > > $this->set('period1', $this->Post->find('all', array( > > > > 'conditions'=>array('user_id'=>$this->Session- > >> read('Auth.User.id'), 'class_period'=>1) > > ))); > > > But I cannot get the information from the periods table. I think this > > would be the equivalent of a Left Join? > > > I would like to echo all periods with a user_id that matches the > > (Auth.User.id). > > > Thanks! > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd 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 > > athttp://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
Re: How to get information in a mysql table from a different controller.
Does your posts table have a field called period or is it period_id? If it's period, that's bad database design. You should change it to period_id so that it relates to the id column in the periods table. Then your problem is an easy one to overcome using table associations. Jeremy Burns Class Outfit http://www.classoutfit.com On 22 Nov 2011, at 18:08, GG wrote: > I have two tables, a posts table, and a periods table. > > The posts table has a user_id, title, body, period. > > The periods table has a user_id, title, period. > > I can easily get the information from the posts table in my > PostsController.php: > > $this->set('period1', $this->Post->find('all', array( > > 'conditions'=>array('user_id'=>$this->Session- >> read('Auth.User.id'), 'class_period'=>1) > ))); > > But I cannot get the information from the periods table. I think this > would be the equivalent of a Left Join? > > I would like to echo all periods with a user_id that matches the > (Auth.User.id). > > Thanks! > > -- > 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
How to get information in a mysql table from a different controller.
I have two tables, a posts table, and a periods table. The posts table has a user_id, title, body, period. The periods table has a user_id, title, period. I can easily get the information from the posts table in my PostsController.php: $this->set('period1', $this->Post->find('all', array( 'conditions'=>array('user_id'=>$this->Session- >read('Auth.User.id'), 'class_period'=>1) ))); But I cannot get the information from the periods table. I think this would be the equivalent of a Left Join? I would like to echo all periods with a user_id that matches the (Auth.User.id). Thanks! -- 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