Find an Organization with denormChildren


#1

I’m trying to fetch Organizations with denormChildren, and I’ve tried the following:

Organization.fetch({filter: “exists(denormChildren)”}) - returns Orgs with denormChildren fields that have empty arrays

Organization.fetch({filter: “denormChildren.length>0”}) - returns error: Field ‘length’ does not exist in expression: ‘meta.tenantTagId == 5 && ((startsWith(typeIdent, ‘PRT:ORG’)) && (denormChildren.length > 0))’ for type 'Organization

Organization.fetch({filter: “exists(denormChildren[0])”}) - returns error: Query with mapp lookup in expression “meta.tenantTagId == 5 && ((startsWith(typeIdent, ‘PRT:ORG’)) && (exists(denormChildren[0])))” is not yet supported; error at 1: 7

Is there something else I can try? What am I missing?


#3

Have you tried

Organization.fetch({
  filter: "exists(denormChildren)", 
  include: "denormChildren.name"
});

or something like that, so it brings back some of the data that’s on denormChildren? Generally, data stored in another table isn’t returned unless explicitly asked for, I believe.


#4

Ok, if I do that it works! If I don’t specify the include, it will still show the field in the console response, but as empty.


#5

@sean.summers FYI that is because in the C3 JavaScript Type System, when calling MyType.make(), all collection fields are automatically instantiated with empty collections if no value is already provided for the field.

I believe this decision was made in order to facilitate writing cleaner code, e.g. I can blindly do:

MyType.fetch().objs.each(obj => console.log(obj.id));

since I know objs will always be defined.

(instead of having to always explicitly check if it is defined):

var fetchResult = MyType.fetch();
if (fetchResult.objs) {
  objs.each(obj => console.log(obj.id));
}