设计模式:Rails 中子状态的父状态聚合
我有一个会议模型,其中有很多参与者。每个参与者都可以对会议采取多项操作(注册、接受、拒绝等)。会议状态(待定、已确认等)取决于每个参与者的最新操作及其自身属性(过期日期等)。
例如,如果所有参与者都接受,则会议状态将为“已确认”。但是,如果在确认会议后,一位参与者提出了新的时间(由于时间冲突),则会议现在将变为“待定”。
我应该如何在会议中模拟状态?我应该序列化(即在事件表中创建latest_state 列)当前状态吗?如果是这样,我如何使用基于子对象动作的状态机?
谢谢。
I have a Meeting model, which has many Participants. Each participant can take several actions against a Meeting (enroll, accept, decline etc.). Meeting status (pending, confirmed etc.) depends on latest action of each participant and its own attributes (expired date etc.)
For example, if all participant accept, then meeting status will be "confirmed". However, if after meeting is confirmed, one participant proposes a new time (because of a time conflict), then meeting now becomes "pending".
How should I model state in Meeting? Should I serialize (i.e., create a latest_state column in events table) current state? If so, how can I use state machine which based on child objects' actions?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的解决方案可能是在更新参与者模型时触发会议状态更新:
如果
Participant
则self.status_changed?
将返回true
的status
属性在更新期间发生了变化Probably the best solution would be to trigger a meeting status update when the Participant model is updated:
self.status_changed?
will returntrue
if theParticipant
'sstatus
attribute changed during the update