问题描述
我具有以下数据库结构:
database:
=> schema1
=> users (with userid)
=> schema2
=> photos (with relation to users.id)
=> schema3
=> photos (with relation to users.id)
(是的,必须有多个具有相同表的模式,因为一个模式代表了照片的自定义“相册”。如果有更好的方法将照片存储在自定义相册中而不是“全部放入”与专辑表相同的架构”,然后告诉我)
现在的问题:
我可以在TypeORM中的user表和photos表之间创建关系,而无需编写“自定义”查询吗?
赞:
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
// HERE THE RELATION LIKE @ManyToMany with the different schemas (maybe there should not be any relation here at all,because of the multiple schemas?
photos: Photo[];
}
@Entity()
class Photo {
@PrimaryGeneratedColumn()
id: number;
@RelationHere?
user: User;
}
那么有没有办法创建类似的关系,或者我是否必须仅将user.id作为数字存储在“照片表”中,而不是使用联接手动编写查询?
还是有办法让我可以做getConnection('schema2').getRepository(Photo).findOne({ where: { id: 123 },relations: ['user'] })
。 (无需编写带有联接的querybuilder)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)