簡體   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