Field in fetch result available also if not populated


on behalf of our customer:

is it somehow possible to have in the fetch result also the fields that are not populated in the type?
When I assign a fetch result to a variable than the objs[i] has only the fields that are populated in the type.


I’m not sure I understand the question. You can use an include spec to traverse references, etc. but not sure what other fields you would expect if they aren’t in the type (not sure if you meant defined rather than populated).


@trothwein I mean defined and NOT populated. Using an include spec the not populated fields are shown with a C3Grid but if you assign the result of a fetch to a variable you can see that the not populated fields are not part of the object


@marcosordi I’d need to see an example of what you are talking about. I can’t think of any reason that c3Grid would show something that if you just expanded the same object returned that field wouldn’t exist.


@JohnCoker could you please provide some info on how a field of a type is managed in JS.
If I have this scenario

var a = MyType.fetch({limit:10,include:"year_to_date”})

if year to date is not populated in the underline DB … a.objs[0].year_to_date is not there at all … there is a way to have it in the object also if it is not populated? so a.objs[0].year_to_date = null


You could use the .at() function which is a “safe access” function. This would be:

MyType.fetch({limit: 10, include: 'year_to_date'}).at("objs[0].year_to_date") will evaluate to either a value or ‘null’ while
MyType.fetch({limit: 10, include: 'year_to_date'}).at("objs.year_to_date") will evaluate to an array of 10 elements each of which is either ‘null’ or a value


We don’t serialize null values (or any “void” values for that matter) to save space and time. So if the value does not come back from fetch, it will not have a property in the JavaScript object. (I.e., hasOwnProperty will return false and access by name will return undefined).

It sounds like you want it to be null (i.e., hasOwnProperty true and access by name returns null). Today we have no way of doing this and would be unlikely to add it without a compelling reason. (It makes the serialized objects larger for one.)

Note that if you use “== null” (double, not triple, equals), you can test for both null and undefined with the same amount of code.

Note that JavaScript is the only language we support which makes a distinction between null and undefined; Java has null and Python has Nil. So most JavaScript code treats undefined and null the same way.