Array of anyof()


#1

Is this possible?

type House {
  animals: [anyof(Dog, Bird)]
}

#2

Have you tried? did you get an error?


#3

It should work. I agree with Riley that you shouldn’t just ask a question like this if you haven’t tried it.


#4

I think posts like this is still valuable, maybe for someone who has never seen this. In the future, I will make sure I post the question and the solution (If I know or I am able to try it).

Here is an example.

c3typ files:

entity type House schema name 'HOUSE' {
  animals: [anyof(Dog, Bird)] schema suffix 'ANMS'
}

entity type Bird schema name 'BIRD' {
  age: int
  wingSpan: double
}

entity type Dog schema name 'DOG' {
  age: int
  legLength: double
}

create data:

Dog.merge({id:"dog1", legLength:10, age:1})
Bird.merge({id:"bird1", wingSpan:10, age: 2})
House.merge({id:"house1", animals: [
  {id:"dogMissing", type:"Dog"}, 
  {id:"dog1", type:"Dog"}, 
  {id:"bird1", type:"Bird"}
]})

fetch on House you would see the links.


#5

I agree that helpful tips are good to post and I would encourage you do things like your last reply. I would, however, say that asking a question that you could easily answer yourself will end up wasting someone else’s time and I would strongly discourage that.