SQL calculations as read only fields in Doctrine 1.2
Consider the following data schema:
Employee:
columns:
name: string(255)
activeSince: date
activeUntil: date
I am working in a system where queries are dynamically constructed by the end user through the process of selecting fields, comparators and values. I would like this table to have a calculated field active
that is true if the current date is between the two date fields.
This of course would be easy when implementing a getter function in PHP was an option, but it isn't because
- I need to filter the database using that field
- The table contains a huge load of records, and selecting all of them and letting PHP do the filtering afterwards is far too heavy. The filtering needs to be done on the database server.
I know that it can be done using by customising the DQL in PHP, but this is also not an option, because the end users can't write additional code. Ideally, I hope for a YAML construct as
Employee:
columns:
name: string(255)
activeSince: date
activeUntil: date
active: calc开发者_开发百科ulated
type: boolean
dql: CURDATE() BETWEEN activeSince AND activeUntil
CURDATE() and BETWEEN are MySQL functions that should work fine in DQL.
Is there anything like this possible in Doctrine 1.2?
精彩评论