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 <[email protected]> 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to