Benjamin Paap
Benjamin Paap

Reputation: 2759

Use a calculated column in a doctrine2 mapping definition

Is it possible in doctrine2 to use a calculated column in the mapping definition? I have for example a table that has a column called quantity and a column unit_price. I want to add a calculated column price to the mapping which will be calculated by multiplying quantity and unit_price. I know that this will only be possible for SELECT statements.

Could this be achieved using doctrine2?

Upvotes: 2

Views: 6694

Answers (1)

Lighthart
Lighthart

Reputation: 3656

This cannot be done with doctrine explicitly.

  1. You have two alternate approaches: Customize the entity that is instanced via doctrine query with a property that has no representation in the database, and use the constructor to calculate the value.
  2. Use a custom hydrator. See: Adding virtual columns to current table in Doctrine?.

Upvotes: 3

Related Questions