Hiya! I've been having a blast with FireCMS v3, and so far all is well. I have found one minor issue, when trying to create a reference to a document within a subcollection whose parent is defined by another property that's within a repeated group property.
Here's a basic example:
import { get } from "lodash";
import { buildCollection } from "@firecms/core";
const exampleCollection = buildCollection({
// Yadda yadda yadda...,
properties: {
example: {
name: "Example",
dataType: "array",
of: {
dataType: "map",
properties: {
parent: {
name: "Parent",
dataType: "reference",
path: "parents",
},
child: ({ propertyKey, values }) => {
// propertyKey is not always defined, so we need to wrap in a conditional
if (propertyKey) {
// Get path relative to parent, since we're in an array
// propertyKey looks something like "example.0.child", so to get the parent
// we need to remove "child" and replace with "parent", and the retrieve
// from the values object.
const parentPropPath = propertyKey.split(".").slice(0, -1);
parentPropPath.push("parent");
const parent = get(values, parentPropPath);
return {
name: "Child",
dataType: "reference",
path: `${parent.pathWithId}/children`,
}
} else {
return {
name: "Child",
dataType: "reference",
path: "parents",
disabled: {
clearOnDisabled: true,
disabledMessage: "Please select a parent",
}
}
}
}
}
}
}
}
});
The propertyKey seems to only sometimes be populated:
Meanwhile, is there a better way to point a reference field to a document's subcollection path?
Hiya! I've been having a blast with FireCMS v3, and so far all is well. I have found one minor issue, when trying to create a reference to a document within a subcollection whose parent is defined by another property that's within a repeated group property.
Here's a basic example:
The
propertyKey
seems to only sometimes be populated:Meanwhile, is there a better way to point a reference field to a document's subcollection path?