Re: How to create models for complex database designs like this?
Can any one create sample app here. http://cakeapp.com/sqldesigners/sql/movie i have created table..but still its displaying celebrity id instead of celebrity name. Raj On Mar 8, 5:40 pm, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
> But celebrity_id is showing id instead of name how > can i get celebrity name instead of id. Only fields named 'title' or 'name' are displayed automatically in lists etc. I appreciate that this answer doesn't directly solve your problem with the 'celebrities' table, but it may be helpful with your 'movies' table. http://book.cakephp.org/view/438/displayField On Mar 8, 12:40 pm, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
assuming your relations are setup correctly in the models, you probably just need to use the recursive in the movies controller. $movies = $this->Movie->find('all', array('recursive'=>2)); that should give you a list of celebs data for each cast. then just use a pr($movies) to see what is in the array. On Mar 8, 9:40 pm, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
Your models is Movie hasMany Cast, Celebrity hasMany Cast dan Cast belongsTo both of Movie and Celebrity, right? if you wants show moview on view.ctp on Cast and included celebrity info, it's simple! you can use contain behavior this is for example: movies_controller.php : (controller) function view($id=null){ .. $movies = $this->Movie->getInfo($id); $this->set(compact('movies')); } movie.php : (model) var $actAs = array('Containable); function getInfo($id){ $result = $this->find('all',array( 'conditions'=>array('Movie.id'=>$id), 'contain'=>array('Cast'=>array( 'fields'=>array('role'),'Celebrity'=>array('fields'=>array('name')) )) )); return $result; } For details, you can reading about containable on book.cakephp.org On Tue, 2009-03-10 at 17:50 -0700, Rajesh wrote: > Is there any other way to redefine database to meet the requirements? > Please help me on this... > > > On Mar 8, 5:40 pm, Rajesh wrote: > > I am working on movie site. Client have movie records in following > > structure. > > > > CREATE TABLE IF NOT EXISTS `movies` ( > > `id` int(50) NOT NULL AUTO_INCREMENT, > > `movieName` varchar(500) NOT NULL, > > `year` int(11) DEFAULT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `celebrities` ( > > `id` int(11) NOT NULL AUTO_INCREMENT, > > `name` varchar(250) NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `casts` ( > > `movie_id` int(50) NOT NULL, > > `role` varchar(200) DEFAULT NULL, > > `celebrity_id` int(11) NOT NULL DEFAULT '0', > > KEY `movieid` (`movie_id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > > > As you can see movies has casts, casts table contains movie_id and > > celebrity_id. celebrities master table is for storing all master > > celebrity names. > > > > Now my problem is i have created models for movie and celebrity like > > movie hasmany cast. In movie page aim getting movie details along > > related casts. But celebrity_is is showing id instead of name how > > can i get celebrity name instead of id. Please help me. > > --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
Is there any other way to redefine database to meet the requirements? Please help me on this... On Mar 8, 5:40 pm, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
any solution? On Mar 9, 3:32 pm, nhathoang nhathoang wrote: > According to me ,your mean use hasmany to get informations of movies and > celebrities with related cast, And you want in [Cast] => > [index]][celebrity_id ] to be replaced [Cast] => [index][celebrity_name], > but in fact it can't, > > relationship in model has all 5 fields class name, foreign key, > condition,field,dependent, there is not any field to concern replace name. > > 2009/3/9 Joe Critchley > > > > > Would it not be better to structure it through a HABTM relationship, > > using "Cast" as your 'with' model? > > > So, Movie HABTM Celebrity through Cast. > > and Celebrity HABTM Movie through Cast. > > > On Mar 8, 12:40 pm, Rajesh wrote: > > > I am working on movie site. Client have movie records in following > > > structure. > > > > CREATE TABLE IF NOT EXISTS `movies` ( > > > `id` int(50) NOT NULL AUTO_INCREMENT, > > > `movieName` varchar(500) NOT NULL, > > > `year` int(11) DEFAULT NULL, > > > PRIMARY KEY (`id`) > > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > > -- > > > CREATE TABLE IF NOT EXISTS `celebrities` ( > > > `id` int(11) NOT NULL AUTO_INCREMENT, > > > `name` varchar(250) NOT NULL, > > > PRIMARY KEY (`id`) > > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > > -- > > > CREATE TABLE IF NOT EXISTS `casts` ( > > > `movie_id` int(50) NOT NULL, > > > `role` varchar(200) DEFAULT NULL, > > > `celebrity_id` int(11) NOT NULL DEFAULT '0', > > > KEY `movieid` (`movie_id`) > > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > > > As you can see movies has casts, casts table contains movie_id and > > > celebrity_id. celebrities master table is for storing all master > > > celebrity names. > > > > Now my problem is i have created models for movie and celebrity like > > > movie hasmany cast. In movie page aim getting movie details along > > > related casts. But celebrity_is is showing id instead of name how > > > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
According to me ,your mean use hasmany to get informations of movies and celebrities with related cast, And you want in [Cast] => [index]][celebrity_id ] to be replaced [Cast] => [index][celebrity_name], but in fact it can't, relationship in model has all 5 fields class name, foreign key, condition,field,dependent, there is not any field to concern replace name. 2009/3/9 Joe Critchley > > Would it not be better to structure it through a HABTM relationship, > using "Cast" as your 'with' model? > > So, Movie HABTM Celebrity through Cast. > and Celebrity HABTM Movie through Cast. > > On Mar 8, 12:40 pm, Rajesh wrote: > > I am working on movie site. Client have movie records in following > > structure. > > > > CREATE TABLE IF NOT EXISTS `movies` ( > > `id` int(50) NOT NULL AUTO_INCREMENT, > > `movieName` varchar(500) NOT NULL, > > `year` int(11) DEFAULT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `celebrities` ( > > `id` int(11) NOT NULL AUTO_INCREMENT, > > `name` varchar(250) NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `casts` ( > > `movie_id` int(50) NOT NULL, > > `role` varchar(200) DEFAULT NULL, > > `celebrity_id` int(11) NOT NULL DEFAULT '0', > > KEY `movieid` (`movie_id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > > > As you can see movies has casts, casts table contains movie_id and > > celebrity_id. celebrities master table is for storing all master > > celebrity names. > > > > Now my problem is i have created models for movie and celebrity like > > movie hasmany cast. In movie page aim getting movie details along > > related casts. But celebrity_is is showing id instead of name how > > can i get celebrity name instead of id. Please help me. > > > --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
Would it not be better to structure it through a HABTM relationship, using "Cast" as your 'with' model? So, Movie HABTM Celebrity through Cast. and Celebrity HABTM Movie through Cast. On Mar 8, 12:40 pm, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
can you give sample models for this database structure please? On Mar 9, 1:20 am, James K wrote: > Assuming you've properly defined all your relationships, it likely has > to do with the name of your foreign key. Cake is usually pretty good > at understanding pluralization spellings, but in this instance, it > probably just doesn't understand that celebrity_id is a foreign key > for celebrities. Specify it in your relationship definition. > > $belongsTo = array('Celebrities' => array('foreign_key' => > 'celebrity_id')) > > On Mar 8, 7:40 am, Rajesh wrote: > > > I am working on movie site. Client have movie records in following > > structure. > > > CREATE TABLE IF NOT EXISTS `movies` ( > > `id` int(50) NOT NULL AUTO_INCREMENT, > > `movieName` varchar(500) NOT NULL, > > `year` int(11) DEFAULT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `celebrities` ( > > `id` int(11) NOT NULL AUTO_INCREMENT, > > `name` varchar(250) NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `casts` ( > > `movie_id` int(50) NOT NULL, > > `role` varchar(200) DEFAULT NULL, > > `celebrity_id` int(11) NOT NULL DEFAULT '0', > > KEY `movieid` (`movie_id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > > As you can see movies has casts, casts table contains movie_id and > > celebrity_id. celebrities master table is for storing all master > > celebrity names. > > > Now my problem is i have created models for movie and celebrity like > > movie hasmany cast. In movie page aim getting movie details along > > related casts. But celebrity_is is showing id instead of name how > > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
You mean i should write it in Movie model right? On Mar 9, 1:20 am, James K wrote: > Assuming you've properly defined all your relationships, it likely has > to do with the name of your foreign key. Cake is usually pretty good > at understanding pluralization spellings, but in this instance, it > probably just doesn't understand that celebrity_id is a foreign key > for celebrities. Specify it in your relationship definition. > > $belongsTo = array('Celebrities' => array('foreign_key' => > 'celebrity_id')) > > On Mar 8, 7:40 am, Rajesh wrote: > > > I am working on movie site. Client have movie records in following > > structure. > > > CREATE TABLE IF NOT EXISTS `movies` ( > > `id` int(50) NOT NULL AUTO_INCREMENT, > > `movieName` varchar(500) NOT NULL, > > `year` int(11) DEFAULT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `celebrities` ( > > `id` int(11) NOT NULL AUTO_INCREMENT, > > `name` varchar(250) NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > > -- > > CREATE TABLE IF NOT EXISTS `casts` ( > > `movie_id` int(50) NOT NULL, > > `role` varchar(200) DEFAULT NULL, > > `celebrity_id` int(11) NOT NULL DEFAULT '0', > > KEY `movieid` (`movie_id`) > > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > > As you can see movies has casts, casts table contains movie_id and > > celebrity_id. celebrities master table is for storing all master > > celebrity names. > > > Now my problem is i have created models for movie and celebrity like > > movie hasmany cast. In movie page aim getting movie details along > > related casts. But celebrity_is is showing id instead of name how > > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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: How to create models for complex database designs like this?
Assuming you've properly defined all your relationships, it likely has to do with the name of your foreign key. Cake is usually pretty good at understanding pluralization spellings, but in this instance, it probably just doesn't understand that celebrity_id is a foreign key for celebrities. Specify it in your relationship definition. $belongsTo = array('Celebrities' => array('foreign_key' => 'celebrity_id')) On Mar 8, 7:40 am, Rajesh wrote: > I am working on movie site. Client have movie records in following > structure. > > CREATE TABLE IF NOT EXISTS `movies` ( > `id` int(50) NOT NULL AUTO_INCREMENT, > `movieName` varchar(500) NOT NULL, > `year` int(11) DEFAULT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `celebrities` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `name` varchar(250) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; > -- > CREATE TABLE IF NOT EXISTS `casts` ( > `movie_id` int(50) NOT NULL, > `role` varchar(200) DEFAULT NULL, > `celebrity_id` int(11) NOT NULL DEFAULT '0', > KEY `movieid` (`movie_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; > > As you can see movies has casts, casts table contains movie_id and > celebrity_id. celebrities master table is for storing all master > celebrity names. > > Now my problem is i have created models for movie and celebrity like > movie hasmany cast. In movie page aim getting movie details along > related casts. But celebrity_is is showing id instead of name how > can i get celebrity name instead of id. Please help me. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---