php - Laravel not executing queries with 'having' clause -


i have manually built large query using various eloquent functions (i.e. $this->newquery()->join....), can't run.

when call

echo $query->tosql(); 

it shows me query. can copy , paste command line mysql client, , runs fine, , returns several rows. when call

echo $query->count(); 

or

echo $query->get()->count(); 

it's showing 0.

i enabled mysql general log see happening. see laravel runs, executes several queries - each has prepare line in log, followed execute line. 1 doesn't.

it appears laravel preparing statement, never executing it. why not?

after testing, have identified line causes problem:

$query->having('book_author_author_id', 'not in', db::raw('('.implode(',',$author_ids).')')); 

it appears queries contain 'having' clause not executed laravel, instead pretends execute them , returns empty collection. going on?

the problems turns out laravel not correctly resolving db::raw statements in having clause. since not allow arrays passed through, has practical effect of making impossible write query having x in (1,2,3). instead, solution several separate having clauses. in case, this:

foreach($author_ids $id) {     $query->having('book_author_author_id', '!=', $id); } 

yet irritating example of eloquent's restricted functionality.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -