ikkez / f3-cortex

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

BETWEEN operator in has() relation filter #128

Open olaulau opened 9 months ago

olaulau commented 9 months ago

Hi ;

The BETWEEN operator doesn't seem to work in a has() relation filter :

$entity->has("service", ["date BETWEEN ? AND ?", "2024-02-01", "2024-02-29"]); // error
$entity->has("service", ["? <= date AND date <= ?", "2024-02-01", "2024-02-29"]); // works

$result = $entity->find(["pupil_id = ?", 12], []);

I get this error :

500 Internal Server Error PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[table][rel_field].BETWEEN '2024-02-01' AND '2024-02-29')' at line 1 [[project_path]/vendor/bcosca/fatfree-core/db/sql.php:230]

of course, the same filter directly on the sub-entity work well : $res2 = $entity2->find(["date BETWEEN ? AND ?", "2024-02-01", "2024-02-29"]);

ikkez commented 9 months ago

I've tested this myself and was not able to reproduce.. it's working fine here.. at least for mysql, postgre and sqlite.. is this a mariaDB only glitch maybe? 🤔

tested with

$author = new AuthorModel();
$author->has('news', ['created_at BETWEEN ? and ?', $time, $time]);
$author->load();