我有两个模型:
PdfAnnotation.js:
module.exports = {
tableName: "pdf_annotations",
primaryKey: "pk_id",
attributes: {
pk_id: {
type: "number",
autoIncrement: true
},
annotation_id: {
type: "string",
unique: true,
required: true,
},
comments: {
collection: "pdfcomments",
via: "fk_annotation_id"
}
}
};
PdfComments.js:
module.exports = {
tableName: "pdf_comments",
primaryKey: "pk_id",
attributes: {
pk_id: {
type: "number",
autoIncrement: true,
},
fk_annotation_id: {
model: "pdfannotations",
},
comment_content: {
type: "string",
},
}
};
当我运行这些代码时:
PdfAnnotations.create({
annotation_id: "test3",
});
PdfComments.create({
fk_annotation_id: 'test3',
comment_content: 'test',
});
我收到了这个错误:
我遵循了文档:https ://sailsjs.com/documentation/concepts/models-and-orm/associations/one-to-many 。我的实现和文档之间的区别是:我通过唯一字段annotation_id(string)而不是主键pk_id(number)将PdfComments用于PdfAnnotations的约束,所以我得到了错误。
由于某些原因我不想使用 annotation_id 作为主键(例如它的类型是字符串)
我对 Sails 及其 ORM 不熟悉,希望得到您的帮助。