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.

ChrisNY
  • 3,917
  • 4
  • 27
  • 31

2 Answers2

0

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

sparrow
  • 147
  • 1
  • 5
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.

Community
  • 1
  • 1
Mike Purcell
  • 19,847
  • 10
  • 52
  • 89