SOME ERROR link image not found, or link not found
(err = null) and model save correctly
Banner.add({
name: {
type: Types.Text,
initial: true,
},
image: {
type: Types.Url,
require: true,
initial: true,
},
link: {
type: Types.Url,
require: true,
initial: true,
},
order: {
type: Types.Select,
default: 0,
initial: true,
numeric: true,
options: [{
value: 1,
label: 'First',
}, {
value: 2,
label: 'Second',
}, {
value: 3,
label: 'Third',
}, {
value: 4,
label: 'Fourth',
}, {
value: 5,
label: 'Fifth',
}, {
value: 0,
label: 'None',
}],
emptyOption: false,
},
});
const model = new Banner.model({});
model.save(err => {
if (err) console.error(err);
else console.log(model);
});
4.1 EXPECTED: SOME ERROR image not found, link not found
4.2 ACTUAL: (err = null) and model save correctly
| Software | Version
| ---------------- | -------
| Keystone | 4.0.0-beta.5
| Node | v9.11.1
@kamontat Keystone 4.0.0-beta.5 was released in Jan 2017. Can you please retest with 4.0.0-beta.8 and confirm if the issue is still reproducible?
Thanks,
Stennie
I already update the newest version, and the bug is still exist.
new Model.model(), you need to pass autokey path (e.g. id) into it. otherwise it will return errorMongoError: E11000 duplicate key error collection: base-website.banners index: id_1 dup key: { : null }
var Banner = new keystone.List('Banner', {
autokey: {
from: 'name image',
path: 'id',
unique: true,
},
track: true,
});
@kamontat Great, thanks for confirming and including details to reproduce.
Regards,
Stennie
you mean required?
@laurenskling Good catch! We're trying to clean up the backlog of Keystone issues to get 4.0 out, so any help greatly appreciated :).
@kamontat, your original model has require:true instead of required:true which is allowing you to save with those fields missing.
If you are using name image as the autokey and both values are null, the unique indexed value will also be null and result in the duplicate key error you've encountered.
If you use the expected required attribute this should not be an issue. You'll also need to edit or remove any documents which have the expected fields missing.
Regards,
Stennie
Most helpful comment
you mean required?