Circular dependency detected in type

#1

When I provision the below module I get the following error:

“Circular dependency detected in type adhoc.SrcQuestion field validAnswers”

What does this error mean? What is a better way to accomplish my goal of having a set of parametric types with dependencies between them>

entity module adhoc {

abstract type Question<T> {
    validAnswers        : [ValidAnswer<T>](question)
}

abstract type Answer<T> {
    source          : T
    question        : Question<T> schema name "QST"
}

abstract type ValidAnswer<T> {
    question    : !Question<T> schema name 'QST'
}


entity type Source schema name 'SRC'

entity type SrcQuestion mixes Question<Source> schema name "SQ"
entity type SrcAnswer mixes Answer<Source> schema name "SA"
entity type SrcValidAnswer mixes ValidAnswer<Source> schema name "VA"

}

0 Likes

#2

This works, but I have to redefine all the important fields… which i don’t like… is this the best way?

entity module adhoc schema name ‘adh’ {

abstract type Question<T> {
    validAnswers        : [ValidAnswer<T>](question)
}

abstract type Answer<T> {
    source          : T
    question        : Question<T> schema name "QST"
}

abstract type ValidAnswer<T> {
    question    : !Question<T> schema name 'QST'
}


entity type Source schema name 'SRC'

entity type SrcQuestion mixes Question<Source> schema name "SQ" {
    validAnswers: [SrcValidAnswer]
}
entity type SrcAnswer mixes Answer<Source> schema name "SA" {
    question: SrcQuestion
}
entity type SrcValidAnswer mixes ValidAnswer<Source> schema name "VA" {
    question: SrcQuestion
}

}

0 Likes

#3

There are 2 issues with your original example:

  1. The Question and Answer types depend on each other and trying to resolve the parameters is causing the error. You can discuss with David/John about better handling if that is an issue:

  2. External reference fields/fkey fields (e.g. Question.validAnswers and ValidAnswer.question) can not be parametric as the db engine needs to be able to fetch on the field’s value type and you can’t fetch on parametric types.

If you use the parameters a little differently, I believe you can accomplish your objective without resorting to what you did in the second attempt. Here is what I came up with and testing it appears to work:

  abstract type Question<VAT, AT> {
      validAnswers   : [VAT](question)
      answers        : [AT](question)
  }

  abstract type Answer<ST, QT> {
      source          : ST
      question        : !QT
  }

  abstract type ValidAnswer<ST, QT> {
      source      : ST
      question    : !QT
  }


  entity type Source schema name 'SRC'

  entity type SrcQuestion mixes Question<SrcAnswer, SrcValidAnswer> schema name "SQ"
  entity type SrcAnswer mixes Answer<Source, SrcQuestion> schema name "SA"
  entity type SrcValidAnswerx mixes ValidAnswer<Source, SrcQuestion> schema name "VA"

This allows you to get the benefit of parameterization and have the reference fields have the correct entity types to allow the db engine to work properly.

0 Likes