pecee-pixie icon indicating copy to clipboard operation
pecee-pixie copied to clipboard

For having() method library adds a prefix

Open mrcnpdlk opened this issue 4 years ago • 1 comments

If the table has alias defined, the having() method adds the prefix before the key. I think it shouldnt.

$qb
    ->newQuery()
    ->table(['p_table'=>'p'])
    ->select([
        'p.id'=>'id',
        $qb->raw('DATE(p.signTime) as docDate')
    ])
    ->having('docDate','=','2021-06-24')
    ->get();

I have the error: Unknown column 'p.docDate' in 'having clause'

mrcnpdlk avatar Jun 24 '21 11:06 mrcnpdlk

It's automatically prefixed to make it easier to add the alias after the fact without changing the entire query (when used in models etc) - when joining another table and so on.

It happening because the query builder doesn't recognize the alias docDate. Maybe the feature should be optional or have the alias automatically parsed from any raw statements.

Thanks for pointing out the issue!

I'll find a fix that'll make everyone happy.

skipperbent avatar Jun 25 '21 16:06 skipperbent