mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-12 17:27:27 +02:00
[#2675] fixed implicit relation display fields serialization
This commit is contained in:
1 parent
7f06816008
commit
af193d440d
33 files changed
+165
-128
No files matched your search
@@ -1417,16 +1417,9 @@ export default class CommonHelper {
|
||||
continue
|
||||
}
|
||||
|
||||
if (CommonHelper.isEmpty(val)) {
|
||||
result.push(missingValue);
|
||||
} else if (typeof val === "boolean") {
|
||||
result.push(val ? "True" : "False");
|
||||
} else if (typeof val === "string") {
|
||||
val = val.indexOf("<") >= 0 ? CommonHelper.plainText(val) : val;
|
||||
result.push(CommonHelper.truncate(val));
|
||||
} else {
|
||||
result.push(val);
|
||||
}
|
||||
val = CommonHelper.stringifyValue(val, missingValue)
|
||||
|
||||
result.push(val);
|
||||
}
|
||||
|
||||
if (result.length > 0) {
|
||||
@@ -1447,14 +1440,51 @@ export default class CommonHelper {
|
||||
];
|
||||
|
||||
for (const prop of fallbackProps) {
|
||||
if (!CommonHelper.isEmpty(model[prop])) {
|
||||
return model[prop];
|
||||
let val = CommonHelper.stringifyValue(model[prop], "");
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
return missingValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringifies the provided value or fallback to missingValue in case it is empty.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @param {String} missingValue
|
||||
* @return {String}
|
||||
*/
|
||||
static stringifyValue(val, missingValue = "N/A") {
|
||||
if (CommonHelper.isEmpty(val)) {
|
||||
return missingValue;
|
||||
}
|
||||
|
||||
if (typeof val === "boolean") {
|
||||
return val ? "True" : "False";
|
||||
}
|
||||
|
||||
if (typeof val === "string") {
|
||||
val = val.indexOf("<") >= 0 ? CommonHelper.plainText(val) : val;
|
||||
return CommonHelper.truncate(val) || missingValue;
|
||||
}
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
return val.join(",");
|
||||
}
|
||||
|
||||
if (typeof val === "object") {
|
||||
try {
|
||||
return CommonHelper.truncate(JSON.stringify(val)) || missingValue;
|
||||
} catch (_) {
|
||||
return missingValue;
|
||||
}
|
||||
}
|
||||
|
||||
return "" + val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rudimentary SELECT query columns extractor.
|
||||
* Returns an array with the identifier aliases
|
||||
|
||||
Reference in new issue
Block a user