Reputation:
I want to create a Category
model that can hold another category
, but having a problem with reference field that I can set my current category to it self
Any suggestions how to achieve hierarchical categories?
Does KeystoneJS
have filter like 'not equal'?
In other hand, maybe I can set default reference field to it self and it will be like a root...
My current code below:
var keystone = require('keystone'), Types = keystone.Field.Types; var PageCategory = keystone.List('PageCategory', { map: { name: 'name' }, autokey : { from: 'name', path: 'key'} }); PageCategory.add({ name: { type: String, required: true, unique: true}, image: { type: Types.CloudinaryImage, label: "Category Image"}, description : { type: Types.Html, wysiwyg: true}, parent: { type: Types.Relationship, ref: "PageCategory", label: "Parent category"} }); PageCategory.relationship({ ref: "PageCategory", path: "parent"}); PageCategory.register();
Upvotes: 5
Views: 1023
Reputation: 127
I think you have misunderstood how Model.relationship()
works.
It has three options:
I think something in line with this will work for you
PageCategory.relationship({ ref: "PageCategory", path: "children", refPath: "parent"});
Upvotes: 0