Friday, May 20, 2011

Re: Confusion with model, belongsTo, and conditions

I'd guess it pulling the list for the Industry table. That would by
default be the id and dispalyField from Industry.

find('list') will let you define the index and label of your choice.
You could point it to the Query fields you actually want.
http://book.cakephp.org/view/1022/find-list

Regards,
Don

On May 20, 2:50 pm, Tony <tonydem...@gmail.com> wrote:
> I have what I think is a simple model and I am trying to apply some
> conditions, but it appears that the conditions are being ignored.
>
> Here is a simplified version of the models (that is, I left out some
> lines for brevity):
>
> Model 1 - Query:
> ---------------
> class Query extends AppModel {
>
>         var $name = 'Query';
>         var $belongsTo = array(
>                 'Industry' => array(
>                         'className' => 'Industry',
>                         'conditions' => array('Industry.code' => '11')
>                 )
>         );
>
> }
>
> ---------------
> Note that, if it matters, the code is defined in the DB as a VARCHAR.
>
> Model 2 - Industry:
> ---------------
> class Industry extends AppModel {
>
>         var $hasMany = array(
>                 'Query' => array(
>                         'dependent' => true
>                 )
>         );
>
> }
>
> ---------------
>
> When I do the following in a controller, I get ALL rows, not just the
> rows filtered by the condition:
>
> $industries = $this->Query->Industry->find('list');
>
> Am I doing something wrong?
>
> Thanks.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate