Recursive Scala Case class Reduction
I tried do it a different way, when you asked this question on StackOverflow.. You find my version below, first I'll try to give you some feedback on your version :


I see you regularly use isDefined together with pattern matching or if / else. I would replace this by matching for Some / None or even better with a combination of map and getOrElse or with fold :

o.map(f).getOrElse(b)
o.fold(b)(f)


These are more ideomatic ways to handle an Option and unwrap the Option for you where you want to use it (calling get on an Option is something you should try to minimize).
It seems like you could have reused newParentId in the places where you wrote s"$parentId.$id", this would mean that newParentId should be placed outside the if else.
I am not sure if you can change the signature of MyCase, but I am not sure what extra the Option brings for elems, but this may be moot if you want to differentiate between None and Map.empty[String, MyCase]], if you don't then no collection or an empty collections is pretty much the same. 




Here's what I came up with :

def getMapWithChildIds(config: Config): Map[String, Seq[String]] = {
  def mkId(prefix: String, key: String): String = 
    if (prefix.isEmpty) key else prefix + "." + key

  def go(map: Map[String, MyCase], prefix: String): Map[String, Seq[String]] =
    map.flatMap { case (key, elem) =&gt; 
      val fullKey = mkId(prefix, key)
      // this will handle an unactive MyCase the same way as a MyCase with no elems
      Option(elem).filter(_.isActive).flatMap(_.elems).fold(
        Map(fullKey -&gt; Seq.empty[String]))(
        submap =&gt; {
          val directSubKeys = submap.keys.map(mkId(fullKey, _)).toList
          // map entry for this key + entries for sub keys
          Map(fullKey -&gt; directSubKeys) ++ go(submap, fullKey)
        })
    }

  go(config.elems, "")
}


Which gives for :

val noMap: Option[Map[String, MyCase]] = None

val config =
  Config("a", true,
    Map(
      "5" -&gt; MyCase("id?5", true, 
        Some(Map(
          "1" -&gt; MyCase("id?5.1", true,
            Some(Map(
              "1" -&gt; MyCase("id?5.1.1", true, noMap),
              "2" -&gt; MyCase("id?5.1.2", true, noMap)
            ))
          ),
          "2" -&gt; MyCase("id?5.2", true, noMap)
        ))
      ),
      "6" -&gt; MyCase("id?6", true, 
        Some(Map(
          "1" -&gt; MyCase("id?6.1", true, noMap)
        ))
      )
    )
  )


The following result :

val map = getMapWithChildIds(config)
// Map[String,Seq[String]] = Map(5.2 -&gt; List(), 5.1.2 -&gt; List(), 5 -&gt; List(5.1, 5.2), 5.1.1 -&gt; List(), 6 -&gt; List(6.1), 6.1 -&gt; List(), 5.1 -&gt; List(5.1.1, 5.1.2))

map.toList.sortBy(_._1).foreach(println)
// (5,List(5.1, 5.2))
// (5.1,List(5.1.1, 5.1.2))
// (5.1.1,List())
// (5.1.2,List())
// (5.2,List())
// (6,List(6.1))
// (6.1,List())