Closed TomTom101 closed 1 year ago
PocketBase doesn't have null
values (with the exception of the json
type) and uses zero defaults.
Relations are expanded only under the expand
property and the original root-level keys are left untouched.
I'm not sure that I understand your use case, but there are no plans to change the resulting format since it will be too confusing (expand is not always available because it depends on the View API rule of the related collection and if we reuse the same key as the id then you may end up in situation where a single prop will have 2 different types - string and object/array).
Thanks Gani!
What I'm after is a json null for unset relational fields. So "relation": null instead of "relation": "":
{
"id": "2euaei6s2bs9kfx",
"created": "2022-11-16 21:36:26.035Z",
"updated": "2022-11-16 21:36:26.035Z",
"collectionId": "wx8ugpt1m8dk2o5",
"collectionName": "items",
"expand": {},
"name": "Some record name",
"relation": null
}
@TomTom101 As mentioned previously, we don't have null
and this is deliberate (see the table of the supported values in https://github.com/pocketbase/pocketbase/releases/tag/v0.3.0; there will be more documentation on this in the new docs with the v0.8.0 release later this week).
Now I understand "with the exception of the json type" ;) Thanks!
When a record with a
Relation
field (e.g. named "relation") has no relation set, the resulting Json returns an empty string:This is a problem when working with freezed and a model
Item
that expects a modelRelation
for the "relation" field.A null value would be more appropriate and not pose a problem when working with freezed.
Side note: Before that works, I additionally need to copy the full record data from the
expand['relation']
field torelation
since the latter would only contain ids, which would neither satisfy theRelation
model. So I am questioning whether it makes sense to replace the (list of) id(s) in a relational field whenexpand=relation
is given with the actual data set:So instead of this (some default field omitted for brevity):
have this instead