In Cake 3 Is there a way to get find('list') to work when containing a related table?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

In Cake 3 Is there a way to get find('list') to work when containing a related table?

heavyKevy
e.g. I have Countries and states each having an Id, abbreviation and name field. And State contaning the country_id.

I would like to filter the states by country_abbreviation as follows:
    public function getListByCountryAbb($abb, $options = []){
            $qry = $this->find('list', ['contain'=>'Countries', 'keyField'=>'States.abbreviation','valueField'=>'States.state']);
            $qry->where(['Countries.abbreviation'=>$abb])->orderAsc('States.state');
            return $qry;
        }

Although the query runs, it returns unusable results.
Is this supposed to work?
Or is there another way I should be doing it?
Thanks in advance.
Regards,
-Kevin

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.