This nested if could be written as

    if parent.id? 
      parentKey = "precondition_#{parent.id}"
    else if parent.key?
      parentKey = parent.key
    else
      parentKey = parent.type