Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeForm可以找到具有关系的()_Javascript_Node.js_Postgresql_Orm_Typeorm - Fatal编程技术网

Javascript TypeForm可以找到具有关系的()

Javascript TypeForm可以找到具有关系的(),javascript,node.js,postgresql,orm,typeorm,Javascript,Node.js,Postgresql,Orm,Typeorm,我第一次使用TypeORM,不幸的是不得不使用JavaScript。文档主要集中在TypeScript上,所以我在尝试获取一个包含所有相关其他条目的条目时遇到了困难 module.exports = { name: "recordings", columns: { id: { type: "uuid", primary: true, generated: "uuid" },

我第一次使用TypeORM,不幸的是不得不使用JavaScript。文档主要集中在TypeScript上,所以我在尝试获取一个包含所有相关其他条目的条目时遇到了困难

module.exports = {
    name: "recordings",
    columns: {
        id: {
            type: "uuid",
            primary: true,
            generated: "uuid"
        },
        title: {
            type: "text",
            unique: true,
            nullable: false
        },
        file: {
            type: "text",
            unique: true,
            nullable: false
        }
    },
    relations: {
        recordingAnnotations: {
            target: "recordingAnnotations",
            type: "one-to-many",
            joinTable: true,
        }
    }
};

module.exports = {
    name: "recordingAnnotations",
    columns: {
        id: {
            type: "uuid",
            primary: true,
            generated: "uuid"
        },
        startsAt: {
            type: "int",
            nullable: false
        },
        endsAt: {
            type: "int",
            nullable: false
        },
        content: {
            type: "text",
            unique: true,
            nullable: false
        }
    },
    relations: {
        recording: {
            target: "recordings",
            type: "many-to-one",
            nullable: false,
            onDelete: "CASCADE"
        }
    }
};
现在我想找到一个包含所有注释的
录制
条目

const repo = conn.getRepository(Recording.name);
const result = await repo.find({
    where: { id },
    relations: [ "recordingAnnotations" ]
});
我试图得到的结果如下所示:

    id: "some-uuid",
    title: "Recording 1",
    file: "some-uuid",
    annotations: [
        { id: "some-uuid", startsAt: 0, endsAt: 10, content: "Hello!" },
        { id: "some-uuid", startsAt: 20, endsAt: 25, content: "Bye!" },
    ]
我得到的错误是:

TypeError:无法读取未定义的属性
'joinColumns'


在录制模式中,不需要joinTable,因为它只适用于多对多关系

relations: {
    recordingAnnotations: {
        target: "recordingAnnotations",
        type: "one-to-many",
        inverseSide: 'recording'
    }
}
我们需要将inverseSide指定为
recording
,因为我们在
recordingAnnotations
模式中添加了
recording
关系,并且许多人将外键放在当前实体表中

在recordingAnnotations模式中

relations: {
    recording: {
        target: "recordings",
        type: "many-to-one",
        nullable: false,
        onDelete: "CASCADE",
        joinColumn: true
    }
}
我们需要指定joinColumn,它将在
recordingAnnotations
表中添加
recordingId
(外键)

另外,下面是使用一对多关系的完整示例: