I took over a project several months ago that involved polymorphic associations that were infinitely deep.. and I’d like to get some help understanding how to operate on the models.
This is a sample of how the models look like: https://gist.github.com/1701475
CallFlow
— RouteByXxxx
—- XxxxOption
There are actually 6 associations to CallFlow (RouteByXxxx) which all have the child(ren) XxxxOption that is a list of options.
schema.rb: https://gist.github.com/1701475
My biggest question: how would I go about updating the target_did in one of the IvrOption records when I only have the DNIS associated with a CallFlow?
Realistically, an association looks like this:
CallFlow (routable_type=RouteByMessage)
-RouteByMessage
–MessageOption (target_routable_type=RouteByIvr)
—RouteByIvr
—-IvrOption (target_routable_type=null, target_did=1112223333)
Something like this should work; just follow the association chain. There’s no checking for nils or anything here, so you’d want to add that, but the idea should hold.