db.collection({
name: "categories",
tree: "adjacency-list",
fields: [
{
interface: "integer",
name: "parentId",
type: "bigInt",
isForeignKey: true,
uiSchema: {
type: "number",
title: '{{t("Parent ID")}}',
"x-component": "InputNumber",
"x-read-pretty": true,
},
},
{
interface: "m2o",
type: "belongsTo",
name: "parent",
foreignKey: "parentId",
treeParent: true,
onDelete: "CASCADE",
target: options.name,
uiSchema: {
title: '{{t("Parent")}}',
"x-component": "AssociationField",
"x-component-props": {
multiple: false,
fieldNames: { label: "id", value: "id" },
},
},
},
{
interface: "o2m",
type: "hasMany",
name: "children",
foreignKey: "parentId",
treeChildren: true,
onDelete: "CASCADE",
target: options.name,
uiSchema: {
title: '{{t("Children")}}',
"x-component": "AssociationField",
"x-component-props": {
multiple: true,
fieldNames: { label: "id", value: "id" },
},
},
},
],
});