【发布时间】:2021-10-11 13:30:01
【问题描述】:
我正在使用 typeorm 并使用存储库来加载实体。我想查找房产及其活跃租户(is_active = true)
在 PropertyTenant 模型中,我有:
@ManyToOne(type => Property)
@JoinColumn({ name: 'property_id', referencedColumnName: 'id' })
property: Property;
在属性模型中,我有:
@OneToMany(
() => PropertyTenant, (propertyTenant: PropertyTenant) => propertyTenant.property
)
propertyTenants: PropertyTenant[];
我尝试过这样的事情:
return await propertyRepository.findOne({
where: {
id: id,
'propertyTenants.is_active': true
},
relations: [
'location', 'location.city', 'location.city.state', 'propertyPurpose', 'propertyAmenities', 'propertyAmenities.amenity',
'propertyTenants', 'propertyTenants.tenant', 'propertyType', 'propertyDocuments', 'propertyDocuments.documentType', 'propertyImages'
]
});
它给出了错误:
No entity column \"propertyTenants.is_active\" was found.
我在文档中找不到任何内容。我不想使用查询构建,因为它返回原始数据,我需要对其进行处理。
有没有办法在@OneToMany 或@ManyToOne 中设置条件?
如何解决?
【问题讨论】: