0

how we can use the computed field in where condition any idea?

suppose

        $query = $this->table1
            ->find('all')
            ->select(['total_count' => '(SELECT count(*) FROM table2 where table2.fid = table1.id)'])
            ->autoFields(true)
            ->contain([
                'table2', 'table3'
                ])
            ->where(['total_count >' 1]);

Column not found: 1054 Unknown column 'total_count' in where

is there way to to use computed field within where condition or how this issue can be resolved any alternate to this?

HaroonAbbasi
  • 126
  • 10

1 Answers1

0

after some search found the answer

By using having, you can use computed field in condition

$query->having(['total_count >' => 0]);
HaroonAbbasi
  • 126
  • 10
  • yes, but having is intended for grouped query, if you want to use the computed field in a where condition take a look at [**this**](http://stackoverflow.com/questions/38462718/cakephp-query-closest-latitude-longitude-from-database/38522403#38522403) answer if it could help – arilia Aug 10 '16 at 09:07