cakephp查找与相关字段排序的顺序

Array
(
        [Site] => Array
            (
                [id] => 1
                [parent_id] => 0
                [title] => test
                [url] => http://www.test.com
                [slug] => www_test_com
                [keywords] => cpc,seo
                [language_id] => 1
            )
        [SiteMeta] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [site_id] => 1
                        [key] => pagerank
                        [value] => 5
                        [created] => 2010-08-03 00:00:00
                    )
             )
)

By using cakephp, I debug my find('all') and returned me above array. I can sort Site field values by order value inside find function how I am able to order also with SiteMeta values

Any ideas? Thanks

you can use a default query with a order condition like this:

$result = $this->Site->find('all', array(
      'order'=>array('SiteMeta.value DESC' , 'Site.value DESC'),
      'recursive'=>1));

Obviously you can put a condition inside the array to retrieve your right result

I'd do this in the Model as part of the association.

$hasMany = array('SiteMeta'=>array('order'=>array('SiteMeta.value'=>'asc')))

You won't have to repeat yourself anywhere then.

I would do it this way (as shown in the Docs)

$result = $this->Site
  ->find()
  ->contain([
    'SiteMeta' => [
      'sort' => ['SiteMeta.pagerank' => 'ASC']
    ]
  ]);