我有两种型号:
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的约束,所以我得到了错误。
出于某些原因,我不想使用注解ID作为主键(例如其类型为字符串)] >>
我对Sails及其ORM并不熟悉,希望能得到您的帮助。
[我有两个模型:PdfAnnotation.js:module.exports = {tableName:“ pdf_annotations”,primaryKey:“ pk_id”,属性:{pk_id:{类型:“ number”,autoIncrement:true},...
尝试这样的事情: