dongxing2692 2013-06-15 16:45
浏览 41

何时/何时在我的MVC应用程序中实现一些COUNT()语句

Ok so I have my CustomerMapper mapping my Customer domain object perfectly but today I was in the middle of some business logic in one of my domain objects which uses my Customer object and I realized I needed to have some sort of

if( $customer->getNumActiveOrders() > self::MAX_NUM_ORDERS )

Currently my Customer object does not have a $numActiveOrders property so I would have to fetch the number of active orders for this customer only when the getNumActiveOrders() method is called.

The confusion is how do I go about doing this without having any database logic in my Customer domain object? Maybe inject a DAO into my Customer object on creation and let it stop database logic leaking into my domain object? I do not really like the idea of having anything database related in my domain objects though so I am unsure about that one.

Maybe I should have a $numActiveOrders property in my object and just set it when my DataMapper fetches the customer? I do not think I will need this value too much, maybe 3 times (if even) in the whole application so I do not want to be doing an extra query every time I create a Customer

How do people do this sort of task efficiently and without leaking database logic into domain objects?

Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?