Tuesday, July 31, 2012

Re: Choose what field show when depth level is 2

You can use Containable behavior and write something like this:

$Office->find('all', array(
   ...
   'contain' => array(//or 'contains' -> check manual ;)
    'Company' => array('fields' => array('name')),
    'Person' => array(
        'fields' => array('mail'),
        'OfficePersonTask' => array( )
             'Office' => array('fields' => 'name'),
             'Task' => array('fields' => 'name'),
        ),
   ),
   ...
));

Or try setting the fields names in $hasMany, $hasOne, etc array http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasone

On Tuesday, July 31, 2012 12:16:38 PM UTC+2, Mariano C. wrote:
In CakePHP 2.1 I have prepared a Json webservice. This is an excerpt of what I get:

    {
       Offices:[
          {
             Office:{
                id:"1",
                Company:{
                   id:"1",
                   name:"ABC Software"
                }
             },
             Person:{
                mail:"sASa@sAAsS.it",
                OfficePersonTask:[
                   {
                      office_id:"1",
                      person_id:"1",
                      task_id:"1"
                   }
                ]
             }
          }
       ]
    } 

What I want is the possibility to show only some field from relative database, so the method that query the database have `$options['fields']` properly setting, so if I want to show person's mail I write:

$options['fields'] = array("Person.mail");

but what if I want to show company's id or company's name whice is one level deeper?

--
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: