Return fkey fields as default in fetch()


#1

I notice that fetch() doesn’t return fkey reference fields as default. I had to manually add them via include in the FetchSpec.

Is there an annotation I can put on the fkey reference field, so fetch will display it as default?


#2

You can find db annotation by doing c3ShowType(Ann.Db)

In this case, you can add an include annotation.

entity type SomeType {

  @db(include='this')
  fkeys: [OtherType] (parent)

}

Now whenever you do SomeType.fetch, fkeys field will be included.


#3

Thanks! This is great.

I tried this. This returns every field from the referenced object, which is potentially huge. Is there a way to just include the id of the referenced objects? I tried @db(include='this.id') , it doesn’t seem to work


#4

try @db(include='id')


#5

@qiwei.li Keep in mind that they don’t come back unless explicitly requested because it requires extra querying. You should only do this if absolutely necessary. Our policy/philosophy is that EVERY fetch should include the fields that it requires to avoid wasting db/cpu/memory/io resources. So I don’t see any particular reason why you should need to do this.