ikkez / f3-cortex

A multi-engine ORM / ODM for the PHP Fat-Free Framework
GNU General Public License v3.0
118 stars 22 forks source link

has() filter escapes SQL syntax #101

Closed exodus4d closed 4 years ago

exodus4d commented 4 years ago

Hi Christian :) After update 0d7754a5897a639e563add6b8d6db53fc0fae677 [29 Oct 2019] -> v1.6.0, I get a SQL Syntax error. Looks like Cortex escapes SQL reserved words like select, from, where, ... I´m pretty sure, we have talked about it a while ago, and you fixed it (0d7754a works fine).

SELECT `id`, 
    `name`
FROM  
     `structure` 
WHERE  
    `systemid` = ? AND   
     `active` = ? AND (
        EXISTS(
            `select` `id` `from` `corporation_structure` `where` ( ( `corporationid` = ? ) ) AND    ( 
                     `corporation_structure`.`structureid`=`structure`.`id`
             )))

Model

$structure = $this->rel('structures');
$structure->has('structureCorporations', [
    0 => '( corporationId = :corporationId )',
     ':corporationId' => 12345
]);
$structures = $structure->find([
    0 => 'systemId = :systemId and active = :active',
    ':systemId' =>12, 
    ':active' => true
 ])
exodus4d commented 4 years ago

Issue should be fixed in the current master