Post default for array

#1

I have the following types. When I fetch B, I don’t see myField, though it is in c3ShowType(B).

I don’t know if the problem is my use of post default or the overwrite of mixes field

type A {
  myField: [string] schema suffix 'ABC'
}

entity type B mixes A schema name 'CBA' {
  myField: [string] post default "['apple', 'orange']"
}
1 Like

#2

Make sure you include “myField” in your include spec. Array fields are not included by default.

0 Likes

#3

I did. The fetch result doesn’t contain myField at all

0 Likes

#4

None of the following works for me

myField: [string] post default ['apple', 'orange']
myField: [string] post default "['apple', 'orange']"
myField: [string] post default ["'apple'", "'orange'"]
0 Likes

#5

Don’t redefine the value type for myField. Instead use ~ to inherit the value type from the mixed in type:

myField: ~ post default ...

(not sure this will fix your issue though)

0 Likes

#6

@qiwei.li This is a bug. Since arrays are never null, we see the empty array and think the value has been set. Can you please file a ticket?

0 Likes

#7

Until that bug gets fixed, you might be able to achieve the behavior you are looking for by implmenting beforeCreate() and/or beforeUpdate() on your type to populate the array.

0 Likes