I'm also looking for some convinient way to avoid invoking "bindModel"
method ..

On Jul 23, 1:52 pm, Alastair <alast...@zanginteractive.com> wrote:
> Hi and many thanks for your help!
>
> This did work, however it doesn't make sense that I've had to do this
> in the first place! It seems like accessing the parent model of a
> child model is broken. I don't know if I'm doing something completely
> wrong but I can access my comments records from the user perfectly
> fine but am unable to access the User from a comment?
>
> Does anyone have any suggestions why this might be?
>
> Cheers,
>
> Alastair
>
> On Jul 23, 8:53 am, "mariusz.lewandowski" <lew...@gmail.com> wrote:
>
> > I had the same issue.
>
> > The resolutions goes like that: in beforeFilter i invoke:
>
> >         public function beforeFilter() {
> >                 $this->pageTitle = 'Portfolio';
> >                 $this->Portfolio->bindModel(array(
> >                                                 'belongsTo' => 
> > array('Category'),
> >                                                 'hasMany' => 
> > array('Image')));
> >         }
>
> > And then you have an access to allrelatedmodels.
>
> > Cheers.
>
> > On 22 Lip, 19:11, Alastair <alast...@zanginteractive.com> wrote:
>
> > > Hoping someone can suggest something here!
>
> > > I have a number of models, which look as follows:
>
> > > Comment
> > > --------------
>
> > > class Comment extends AppModel
> > > {
>
> > >         var $name = 'Comment';
> > >         var $validate = array(
> > >                 'body' => array('rule' => 'notEmpty')
> > >         );
>
> > >         var $belongsTo = array(
> > >                 'User' => array(
> > >                         'className' => 'User',
> > >                         'foreignKey' => 'user_id',
> > >                 ),
> > >                 'Post' => array(
> > >                         'className' => 'Post',
> > >                         'foreignKey' => 'post_id',
> > >                 ),
> > >         );
>
> > > }
>
> > > Post
> > > -------
>
> > > class Post extends AppModel
> > > {
>
> > >         var $name = 'Post';
> > >         var $validate = array(
> > >                 'title' => array('rule' => 'notEmpty'),
> > >                 'body' => array('rule' => 'notEmpty')
> > >         );
>
> > >         var $hasMany = array('Comment');
>
> > > }
>
> > > User
> > > -------
>
> > > class User extends AppModel {
>
> > >         var $actsAs = array('Acl' => array('requester'));
> > >         var $hasOne = 'Member';
> > >         var $name = 'User';
>
> > >         var $belongsTo = array('Group');
>
> > >         var $hasMany = array(
> > >                 'Comment' => array(
> > >                         'className' => 'Comment',
> > >                         'foreignKey' => 'user_id'
> > >                 )
> > >         );
>
> > > }
>
> > > I'm calling the following find in my Posts controller:
>
> > > $comments = $this->Comment->find('all', array('recursive' => 2));
>
> > > I've declared var $uses = array('Post', 'Comment','User'); at the top
> > > of the posts controller.
>
> > > All I'm getting returned is an array of comments but not theirrelated
> > > users.
>
> > > Can anyone suggest why this might be?
>
> > > Many thanks!
>
> > > Alastair
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to