CTE cannot perform association join on "next" because it does not have a schema in query

I am trying to create an CTE query, as follow:

initial_query =
      query
      |> join(:inner, [course: course], cm in assoc(course, :course_modules), as: :course_modules)
      |> get_modules(projection)

    next_query =
      (from c in Course, as: :course)
      |> join(:inner, [c], cm in "next",
        on: c.course_id == cm.course_id and c.order == cm.order + 1,
        as: :course_modules
      )
      |> get_modules(projection)

    cte_query =
      initial_query
      |> union_all(^next_query)

    query = {"next", Course }
    |> recursive_ctes(true)
    |> with_cte("next", as: ^cte_query)

However I am getting the following error: cannot perform association join on "next" because it does not have a schema in query


     from c0 in Lego.Course,
       as: :course,
       join: n1 in "next",
       as: :course_modules,
       on: c0.course_id == n1.course_id and c0.order == n1.order + 1,
       left_join: m2 in assoc(n1, :module),
       as: :module,
       order_by: [asc: n1.order]

I am following the docs with state:

If you don’t have any Ecto schema pointing to the CTE table, you can pass a tuple with the CTE table name as the first element and an Ecto schema as the second element. This will cast the result rows to Ecto structs as long as the Ecto schema maps to the same fields in the CTE table:

Thanks in advanced

I suspect you’ll need to make this join explicit (table & on) - seems like the casting to a schema is there, but not the using the other schema metadata