<p>What is the best way of working with calculated fields of Propel objects?</p>

<p>Say I have an object "Customer" that has a corresponding table "customers" and each column corresponds to an attribute of my object. What I would like to do is: add a calculated attribute "Number of completed orders" to my object when using it on View A but not on Views B and C.</p>

<p>The calculated attribute is a COUNT() of "Order" objects linked to my "Customer" object via ID.</p>

<p>What I can do now is to first select all Customer objects, then iteratively count Orders for all of them, but I'd think doing it in a single query would improve performance. But I cannot properly "hydrate" my Propel object since it does not contain the definition of the calculated field(s).</p>

<p>How would you approach it?</p>

Add an attribute "orders_count" to a Customer, and then write something like this:
```
```
class Order {
...
  public function save($conn = null) {
    $customer = $this->getCustomer();
    $customer->setOrdersCount($customer->getOrdersCount() + 1);
    $custoner->save();
    parent::save();
  }
...
}
```
```
You can use not only the "save" method, but the idea stays the same. Unfortunately, Propel doesn't support any "magic" for such fields.