Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Possible bug in Model/Module find_all() using BETWEEN?

edited August 2015 in Bug Reports
Strange behaviour using BETWEEN in simple module:
$date = '2015-07-09'; $conflicts = $this->find_all("'{$date}' BETWEEN bookingStartDate AND bookingEndDate");
Produces a MySQL error. The generated query has backticks surrounding the $date
SELECT `assets_bookings`.*, `assets`.`assetTitle` AS `property` FROM (`assets_bookings`) LEFT JOIN `assets` ON `assets`.`assetID` = `assets_bookings`.`bookingAssetID` WHERE `'2015-07-09'` BETWEEN bookingStartDate AND bookingEndDate
In my code, the JOIN is part of what I have in _common_query().

The alternative MySQL notation that does the same job works fine:
$conflicts = $this->find_all("bookingStartDate >= '{$date}' AND bookingEndDate <= '{$date}'");

As you might expect, find_one() does the same thing.


  • That's a good workaround, thanks.

    Still smacks of being a bug in Fuel though... thoughts Admin?
  • edited 3:47AM
    This may be something inside CI. The MY_Model::find_within method uses something to disable the protect_identifiers which you could try calling before using find_all() (which is really just a wrapper around some CI Active Record):
    $_protect_identifiers = $this->db->_protect_identifiers; $this->db->_protect_identifiers = FALSE; $date = '2015-07-09'; $conflicts = $this->find_all("'{$date}' BETWEEN bookingStartDate AND bookingEndDate"); $this->db->_protect_identifiers = $_protect_identifiers; // set it back
Sign In or Register to comment.