manyThrough relationship with aggregate function


#1

I have manyThrough relationship

learningLectureStat() {
    return this.manyThrough(
      "App/Models/learningLecture",
      "learningLectureStat",
      "cer_id",
      "cer_id",
      "cer_id",
      "cer_id",
    )
  }

I want to query from database like

static scopeWithLearningLectureStat(query) {
    return query.with("learningLectureStat", builder => {
      builder.sum("lels_learningStat as timeSpent")
      builder.groupBy("lec_id")
      builder.groupBy("lels_date")
      builder.orderBy("lels_id", "desc")
    })
  }

I got the error as - ER_NONUNIQ_TABLE: Not unique table/alias: ‘tbl_learning_lecture’