php-activerecord
php-activerecord copied to clipboard
Timestamps randomly returned as strings
I haven't been able to track down why, but over the past couple months we've seen instances where our timestamp columns aren't DateTime objects, but instead are strings. The occurrence so far seems to show up in random places.
I encountered a similar problem while updating the library. Suddenly, my code began to throw an error that the date field is a string and not a DateTime object.
I remembered that the previous version was a bit fixed for me to work correctly with PostgreSql. After transferring this fix, everything works correctly. Perhaps the date fields remain strings due to some kind of hidden error.
My case is that the PostgreSQl adapter does not read the table structure that is outside the public schema. I fix the Table.php:
private function get_meta_data() { // as more adapters are added probably want to do this a better way // than using instanceof but gud enuff for now $quote_name = !($this->conn instanceof PgsqlAdapter);
//$table_name = $this->get_fully_qualified_table_name($quote_name);
$table_name = $this->get_fully_qualified_table_name_fix($quote_name);
$conn = $this->conn;
$this->columns = Cache::get("get_meta_data-$table_name", function() use ($conn, $table_name) { return $conn->columns($table_name); });
}
and add in the same place:
public function get_fully_qualified_table_name_fix($quote_name=true) { $table = $quote_name ? $this->conn->quote_name($this->table) : $this->table;
/*if ($this->db_name)
$table = $this->conn->quote_name($this->db_name) . ".$table";*/
return $table;
}
Maybe this information will be useful to someone.