Saturday, October 29, 2011

Re: Problem with unbindModel

killer advice!

way better than unbind.....thanks euromark :)

On 28 Okt., 00:49, euromark <dereurom...@googlemail.com> wrote:
> you can use the containable behavior
> its the fastest and cleanest approach
>
> On 27 Okt., 22:47, Tomfox Wiranata <tomfox.wiran...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I have two models: user and book. in my user model i defined this
> > object:
>
> > 'HistoryAll' =>
> >             array(
> >                 'className'              => 'Book',
> >                 'joinTable'              => 'books_users',
> >                 'foreignKey'             => 'fk_user_id',
> >                 'associationForeignKey'  => 'fk_book_id',
> >                 'fields'                                =>
> > array('fk_user_id','id','title','description'),
> >                 'conditions'             => array ('locked = false'),
> >                 'order'                  => 'BooksUser.created desc',
> >                 'limit'                  => '',
> >                 'unique'                 => false
>
> > as you can see there is a join with my books model, where i have
> > defined those objects (among others)
>
> > var $hasMany = array(
> >                 'BookContact' => array(
> >                 'className' => 'BookAdditionalInformation',
> >                 'foreignKey' => 'fk_book_id',
> >                 'conditions' => array('is_contact' => true),
> >                 'order' => array('type'),
> >                 'dependent' => 'true'
> >                 ),
>
> > now in my view i have dozens of objects i retrieve from the database
> > and I dont need many of those. this is how the debug looks like
>
> > app\views\users\history.ctp (line 70)
> > Array
> > (
> >     [fk_user_id] => 76
> >     [id] => 208
> >     [title] => book 1
> >     [description] => test
> >     [created] => 2011-10-11 23:19:40
> >     [hash] => d95e7a24d1b20598eb96aecadcf215e5ca7
> >     [BooksUser] => Array
> >         (
> >             [fk_user_id] => 74
> >             [fk_book_id] => 208
> >             [created] => 2011-11-09 23:56:44
> >             [id] => 667
> >             [visible] => 0
> >         )
>
> >     [User] => Array
> >         (
> >             [username] => bookworm
> >             [firstname] => Martin
> >             [id] => 763
> >         )
>
> >     [BookContact] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [fk_book_id] => 208
> >                     [title] => booker is book
> >                     [value] => i...@kyle.de
> >                     [type] => email
> >                     [id] => 1907
> >                     [is_contact] => 1
> >                 )
>
> >             [1] => Array
> >                 (
> >                         More data
> >                 )
>
> >             [2] => Array
> >                 (
> >                         Even more…
> >                 )
>
> >             [3] => Array
>
> > so how do i unbind BookContact??
>
> > I tried:          $this->User->Book->unbindModel('hasMany' =>
> > array('BookContact'));
> > I got:            undefined object User::Book
>
> > I tried:         $this->User->unbindModel('hasMany' =>
> > array('BookContact'));
> > I got            still BookContact as binded
>
> > fyi: my php code
> > =========================
>
> > $this->User->recursive = 2;
>
> > $User = $this->User->findById($id);
> >                 $this->set('user', $User);
>
> > in my view:
> > foreach($user['HistoryAll'] as $all):
>
> > I appreciate your effort and help...thanks...a bunch :)

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: