[eluser]tazoony[/eluser]
Hi,
I had some problems with using *between* methods from Datamappers when values are non-integers (as dates). Then I fixed it simply by overloading
_where_between() method in my
DataMapper_Extra class that extends
DataMapper class :
Code:
/**
* Where Between
*
* Called by where_between(), or_where_between(), where_not_between(), or or_where_not_between().
* Corrected with adding quotes for non-integer values (dates)
*
* @ignore
* @param string $key A field to check.
* @param mixed $value value to start with
* @param mixed $value value to end with
* @param bool $not If TRUE, use NOT IN instead of IN.
* @param string $type The type of connection (AND or OR)
* @return DataMapper Returns self for method chaining.
*/
protected function _where_between($key = NULL, $value1 = NULL, $value2 = NULL, $not = FALSE, $type = 'AND ')
{
$type = $this->_get_prepend_type($type);
// Add quotes for non-integer values
$_ = "'";
if ( is_int($value1) && is_int($value2) )
{
$_='';
}
$this->db->dm_call_method('_where', "`$key` ".($not?"NOT ":"")."BETWEEN $_".$value1."$_ AND $_".$value2."$_", NULL, $type, NULL);
// For method chaining
return $this;
}
Hope it will be helpful for you too.
Joffrey