Re: model links, question from noob.

2010-02-11 Thread jodator
Add containable behavior (http://book.cakephp.org/view/474/
Containable)

then:

$this-Fest-find('first',
  array(
   'conditions' = array(
 'Fest.id' = $id,
   ),
   'contain' = array(
  'Linup' = array(
'order' = array('Lineup),
//other stuff
  ),
  //'Category' is not fetched
),
  )
);

ps.; why do you have:

'foreignKey' = 'category' // not 'category_id' ??

On Feb 11, 2:41 pm, johnbl4ck unknw...@gmail.com wrote:
 Hi all!

 I love this feature of cakephp, however i have some questions.

 this is my model:

 class Fest extends AppModel {
         var $name = 'Fest';
         var $useTable = 'fests';

         var $belongsTo = array(
                 'Category' = array(
                         'className' = 'Category',
                         'foreignKey' = 'category'
                 )
         );

         var $hasMany = array(
                 'Lineup' = array(
                         'className' = 'Lineup',
                         'foreignKey' = 'fest_id'
                 )
         );

 }

 as you can see it defines hasMany link, so when i do $this-Fest-

 find('all') it pulls Lineup for each item of Fest.

 The question is:
 Lineup is also linked to Artist by belongsTo bond. Is it possible to
 fetch all required data (Fest-Lineup-Artist) in one single Fest
 call? That would be awesome but i don't know how to do that and stick
 to

                 $f = $this-Fest-find($id);
                 $l = $this-Lineup-find('all', array('conditions'= 
 array('fest_id'
 = $id), 'order' = 'Lineup.status DESC'));

 which i think is not the best solution.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: model links, question from noob.

2010-02-11 Thread johnbl4ck
Great, you saved me a lot of time! And to answer your question, well i
just missed it, yes, it's more logical to name that field category_id

On 11 фев, 19:41, jodator joda...@gmail.com wrote:
 Add containable behavior (http://book.cakephp.org/view/474/
 Containable)

 then:

 $this-Fest-find('first',
   array(
    'conditions' = array(
      'Fest.id' = $id,
    ),
    'contain' = array(
       'Linup' = array(
         'order' = array('Lineup),
         //other stuff
       ),
       //'Category' is not fetched
     ),
   )
 );

 ps.; why do you have:

 'foreignKey' = 'category' // not 'category_id' ??

 On Feb 11, 2:41 pm, johnbl4ck unknw...@gmail.com wrote:



  Hi all!

  I love this feature of cakephp, however i have some questions.

  this is my model:

  class Fest extends AppModel {
          var $name = 'Fest';
          var $useTable = 'fests';

          var $belongsTo = array(
                  'Category' = array(
                          'className' = 'Category',
                          'foreignKey' = 'category'
                  )
          );

          var $hasMany = array(
                  'Lineup' = array(
                          'className' = 'Lineup',
                          'foreignKey' = 'fest_id'
                  )
          );

  }

  as you can see it defines hasMany link, so when i do $this-Fest-

  find('all') it pulls Lineup for each item of Fest.

  The question is:
  Lineup is also linked to Artist by belongsTo bond. Is it possible to
  fetch all required data (Fest-Lineup-Artist) in one single Fest
  call? That would be awesome but i don't know how to do that and stick
  to

                  $f = $this-Fest-find($id);
                  $l = $this-Lineup-find('all', array('conditions'= 
  array('fest_id'
  = $id), 'order' = 'Lineup.status DESC'));

  which i think is not the best solution.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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