1

Suppose you declare a simple "license" table in a doctrine schema, consisting say of 3 fields, name, licenseNumber, expirationDate.

You can create a simple query to instantiate the collection of license objects. But what if you wanted to add a "virtual" field to it, for example,select *, (now() > expirationDate) as expired from license (in DQL, I'm using SQL as shorthand here).

Is there any way to get doctrine to make the "expired" calculated field retrievable as an attribute of the object? This is a trivial example to illustrate the point, but it could be quite helpful for more complicated calculated queries, or else I'm misunderstanding something.

1
  • Which version of symfony and doctrine are you using?
    – Maerlyn
    Apr 3, 2012 at 8:35

2 Answers 2

0

No, there is no way to do what you are asking without adding a custom method to hydrate the "virtual column". Take a look at this SO post, as it gives an excellent example on how to hydrate arrays with your "virtual column".

You can also add the "virtual column" as a member object to the respective class and hydrate it like this example demonstrates.

1
  • Were you able to figure out the custom hydration? Apr 6, 2012 at 5:27
0

You can also use a view with such a column and map your model to it instead of a db table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.