Symfony app - how to add calculated fields to Propel objects?

前端 未结 5 779
清酒与你
清酒与你 2021-02-10 03:41

What is the best way of working with calculated fields of Propel objects?

Say I have an object \"Customer\" that has a corresponding table \"customers\" and each column

5条回答
  •  遇见更好的自我
    2021-02-10 04:10

    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.

提交回复
热议问题