I’m trying to use Doctrine with a poorly designed PostgreSQL database. Some tables have DATE and TIME fields that should be TIMESTAMP fields.
Is it possible map a pair of DATE and TIME fields into a DateTime property on my classes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could create a method
getTimestamp()that would return anew \DateTime($this->getDate()->format('Y-m-d') . ' ' . $this->getTime()->format('H:i:s'))object and create asetTimestamp(\DateTime $date)method that would set the two values by get date and time separatly.or something like that. You can then exclusively use the
get/setTimestamp()in your code.DQL
You pass your timestamp as a single param and you bind 2 params like this :
You might have to wrap your params values in a
new \DateTime()since doctrine needs a DateTime instance as date, time and timestamp.This give you a simple interface to support in your code, but allow to make abstraction of the database schema.