Closed vfermino closed 9 years ago
1) I don’t think you need the below entry
Product.relationship({ path: 'collections', ref: 'Collection', refPath: 'collection' });
2) Alter your schema definition of Product so the ‘collections’ field will be a Relationship instead of Type.Select collections: { type: Types.Relationship, ref: 'Collection', many: true },
On Monday, 22 September 2014 at 10:21 pm, vfermino wrote:
Hello. I am new to JS, and I've been trying to make a catalog-like website, and I have two models: Product (which represents individual products) and Collection (which is a category or product line, so it can group many products).
var keystone = require('keystone'), Types = keystone.Field.Types; var Product = new keystone.List('Product', { autokey: { path: 'slug', from: 'name', unique: true }, map: { name: 'name' }, defaultSort: '-createdAt' }); Product.relationship({ path: 'collections', ref: 'Collection', refPath: 'collection' }); Product.add({ name: { type: String, required: true }, collections: { type: Types.Select, options: [keystone.List.Collection] }, // My big problem publishedDate: { type: Date, default: Date.now }, banner: { type: Types.CloudinaryImage }, content: { brief: { type: Types.Html, height: 150 }, extended: { type: Types.Html, height: 400 } }, icon: { type: Types.CloudinaryImages } }); Product.register(); The question for me is: how do I make an array out of the Collections to give the user a dropdown of the Collections an item can belong to? I will probably change them to a list of checkboxes, though. Thanks.
— Reply to this email directly or view it on GitHub (https://github.com/keystonejs/keystone/issues/648).
Thanks. I did just that and it helped.
Hi, I am facing some problem with array field. I am trying to add multiple categories to my movie schema.Below is how I have added that categories field to Movie schema.
Movie.schema.add({
categories: [{
name: String
}]
});
In the POST, I am getting all the selected categories Ids in array format. I am using updatehandler
to save that.
but is give me error UpdateHandler.process called with invalid field path: categories
.
I tried to set that at the time of model object creation like
var newMovie = new Movie.model({
categories: req.body.categories
}),
How can I use array fields to add multiple items to it and save/update to mongo database ??
Any help ??
@TejasCMehta could you open a new issue for your question. Or use the irc channel/google group/stackoverflow tag
Hello. I am new to JS, and I've been trying to make a catalog-like website, and I have two models: Product (which represents individual products) and Collection (which is a category or product line, so it can group many products).
var keystone = require('keystone'), Types = keystone.Field.Types; var Product = new keystone.List('Product', { autokey: { path: 'slug', from: 'name', unique: true }, map: { name: 'name' }, defaultSort: '-createdAt' }); Product.relationship({ path: 'collections', ref: 'Collection', refPath: 'collection' }); Product.add({ name: { type: String, required: true }, collections: { type: Types.Select, options: [keystone.List.Collection] }, // My big problem publishedDate: { type: Date, default: Date.now }, banner: { type: Types.CloudinaryImage }, content: { brief: { type: Types.Html, height: 150 }, extended: { type: Types.Html, height: 400 } }, icon: { type: Types.CloudinaryImages } }); Product.register();
The question for me is: how do I make an array out of the Collections to give the user a dropdown of the Collections an item can belong to? I will probably change them to a list of checkboxes, though. Thanks.