Propel and the zero date issue

Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL (‘0000-00-00’) and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what I did to solve it.
So what’s all the fuzz about? It’s about a query like this:

This query gathers contracts which are active (e.g. valid, started and not ended) at this moment.
In Propel 1.5.4 this code translates to the following query:

However, in Propel 1.6.0 the code translates to:

Instead of putting 0000-00-00 in the query, the date is translated to -0001-30-11. (Should I read this as 30th of November 1969?)
As my code relies heavily on the outcome of the query, I had to find a quick solution. After some informing on IRC I learned that there seems to be an issue concerning these zero dates (Propel prefers using NULL instead of 0000-00-00, but my application is a legacy application).
The actual solution comes down to writing the query by hand, using the (Debug)PDO instance for querying and using the PropelObjectFormatter to hydrate the results back into the objects you want to be working with.


And that’s it. It cost me a little time to figure this out, but my deployment was saved.

Slight note
Please note that Propel normally puts all fields separately in the SELECT statement, but that I’ve shortened it by putting down the * sign

Getagged , ,

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *