繁体   English   中英

更新Rails中的多态关联

[英]Updating a polymorphic association in rails

几个月前,我接手了一个项目,该项目涉及无限深的多态关联。.我想获得一些帮助,以了解如何在模型上进行操作。

这是模型外观的示例: https : //gist.github.com/1701475

呼叫流
-RouteByXxxx
---- Xxxx选项

实际上,有6个与CallFlow(RouteByXxxx)的关联,所有关联都具有作为子选项列表的子级XxxxOption。

schema.rb: https ://gist.github.com/1701475

我最大的问题:当我仅将DNIS与CallFlow相关联时,如何在IvrOption记录之一中更新target_did?

实际上,一个关联如下所示:

呼叫流程(routable_type = RouteByMessage)
-RouteByMessage
--MessageOption(target_routable_type = RouteByIvr)
--- RouteByIvr
---- IvrOption(target_routable_type = null,target_did = 1112223333)

这样的事情应该起作用; 只需遵循关联链。 这里没有检查nil或任何东西,因此您想添加它,但是这个想法应该成立。

call_flow = CallFlow.find_by_dnis(params[:dnis])
target_routable = call_flow.routable.options.first(:conditions => ["target_routable_type = ?", 'route_by_ivr']
ivr_option = target_routable.options.find(:conditions => (whatever))
ivr_option.update_attributes :target_did => 112233

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM