Permalink
Browse files

GH-45 fixed conditions to accept DateTime values

  • Loading branch information...
kla committed May 19, 2010
1 parent 408faa6 commit 26e40f43bc2ad60323eeb1d48f00deba5f303789
Showing with 24 additions and 5 deletions.
  1. +1 −1 lib/Expressions.php
  2. +10 −2 lib/SQLBuilder.php
  3. +1 −1 lib/Table.php
  4. +11 −0 test/ActiveRecordFindTest.php
  5. +1 −1 test/helpers/config.php
View
@@ -180,4 +180,4 @@ private function quote_string($value)
return "'" . str_replace("'","''",$value) . "'";
}
}
?>
?>
View
@@ -89,7 +89,15 @@ public function bind_values()
public function get_where_values()
{
return $this->where_values;
$conn = $this->connection;
// there might be a better place to do this filtering. here will do for now
return collect($this->where_values,function($value) use ($conn)
{
if ($value instanceof \DateTime)
return $conn->datetime_to_string($value);
return $value;
});
}
public function where(/* (conditions, values) || (hash) */)
@@ -371,4 +379,4 @@ private function quoted_key_names()
return $keys;
}
}
?>
?>
View
@@ -536,4 +536,4 @@ private function set_setters_and_getters()
}
}
};
?>
?>
@@ -442,5 +442,16 @@ public function test_find_by_pk_should_not_use_limit()
Author::find(1);
$this->assert_sql_has('SELECT * FROM authors WHERE author_id=?',Author::table()->last_sql);
}
public function test_find_by_datetime()
{
$now = new DateTime();
$arnow = new ActiveRecord\DateTime();
$arnow->setTimestamp($now->getTimestamp());
Author::find(1)->update_attribute('created_at',$now);
$this->assert_not_null(Author::find_by_created_at($now));
$this->assert_not_null(Author::find_by_created_at($arnow));
}
};
?>
View
@@ -18,7 +18,7 @@
$cfg->set_connections(array(
'mysql' => 'mysql://test:test@127.0.0.1/test',
'pgsql' => 'pgsql://test:test@127.0.0.1/test',
'oci' => 'oci://test:test@127.0.0.1/dev',
'oci' => getenv('PHPAR_OCI') ? getenv('PHPAR_OCI') : 'oci://test:test@127.0.0.1/dev',
'sqlite' => 'sqlite://test.db'));
$cfg->set_default_connection('mysql');

0 comments on commit 26e40f4

Please sign in to comment.