Thank you.  I have applied the Containable behavior to the specific
query.  Jury is still out on how I'll choose to implement it
throughout the system.

On Apr 15, 12:50 am, Jeremy Burns <jeremybu...@me.com> wrote:
> Two options...
>
> Use $this->Service->find(); instead
>
> Or...
>
> I would use the Containable behaviour - this seems like such a recurring 
> piece of advice from me - but it really does solve a heap of issues! If you 
> don't use contain, you are more or less letting Cake decide what data to 
> bring back - and I have worked on a few second hand systems where a single, 
> simple, find statement has brought back almost the entire database - 
> seriously. Imagine what that does to performance...
>
> Create app_model.php and store it in the same folder as app_controller.php.
>
> class AppModel extends Model {
>
>         var $actsAs = array('Containable');
>         var $recursive = -1;
>
> }
>
> Now, you have switched off recursion across the system, so by default a find 
> will only bring back the 'current' model's table (in other words, no 
> associated data).
> This might mean you have to revisit some existing queries. But the benefit is 
> that you can now do really finds. In your case:
>
> $this->Service->find(
>         'all',
>         array(
>                 'conditions' => array('Service.id' => $id),
>                 'fields' => array(..field list...),
>                 'Contain' => array(
>                         'Credential' =>
>                                 'fields' => array(...field list...),
>                                 array(
>                                         'CredentialType' => array(
>                                                 'fields' => array(...field 
> list...)
>                                         )
>                                 )
>                 )
>         )
> );
>
> You could also just put the containable behaviour inside your Service model, 
> but I don't see the point of doing something so beneficial on just a portion 
> of your app.
>
> Jeremy Burns
> jeremybu...@me.com
>
> On 14 Apr 2010, at 22:01, Joshua Taylor wrote:
>
>
>
> > Situation:
>
> > Viewing a service.
>
> > A service has credentials.
>
> > Credentials have a credential type.
>
> > I'm using $service = $this->Service->findById($id); to set all the
> > data for my view.  I have all the database associations set up
> > correctly (I think):
>
> > Service hasMany Credential.
> > Credential belongsTo Service, CredentialType.
> > CredentialType hasMany Credential.
>
> > How can I get it to retrieve CredentialType.title, so I can display
> > the title instead of the Credential.credential_type_id value, which is
> > worthless to a person viewing the service?
>
> > I really don't want to use recursive = 2 (although it works), because
> > it creates enormous database overhead!  (55 queries vs. 25)
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 
> > athttp://groups.google.com/group/cake-php?hl=en
>
> > To unsubscribe, reply using "remove me" as the subject.

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

Reply via email to