Comments (3)
potentially yes?
I haven't used or worked on this package now for a very long time. I know children relationships 100% work with hydration, creation and updating as that's what I built it for. I know parent relationships have an issue and I have attempted to correct but it got messy and my time was limited.
I reckon you should be able to use a 2 way child setup. Both parent and child decorators use the same methods so 2 children entities should work 🤞
In your scenario however I don't think you'd need polymorphic relationships, you could quite easily have tags which relate separately to images and videos. However if you wanted to do the reverse where you fetched tags and the tag could relate to videos and images together. Then yes you would need polymorphic relationships setup in a custom many-to-many table. I usually make a custom entity for this type of setup so I can define different properties in the joiner table for queries.
export class TagEntity {
@OneToMany(() => TagPolymorphicEntity, source => source.tag)
source: TagPolymorphicEntity;
@Column()
name: string;
}
export class TagPolymorphicEntity {
@PolymorphicParent(() => [VideoEntity, ImageEntity], {
eager: false,
})
resource: VideoEntity | ImageEntity;
@OneToMany(() => TagEntity, tag => tag.source)
tag: TagEntity;
}
export class VideoEntity {
@PolymorphicParent(() => TagPolymorphicEntity, {
eager: false,
})
tagSource: TagPolymorphicEntity;
}
This is sort of what you want? I'm not sure if the correct decorator was children or parent but this should work 🤞
Also you might not like this example so you could make the TagPolymorphicEntity
a JoinTable definition instead. I just like it so I can explicitly get properties and joins etc like so video.tagSource.tag.name
and so on.
Let me know if this works! It's not the best library in the world and it definately wasn't finished!
from typeorm-polymorphic.
First of all, thanks for the response. I have to use the repository in order to make the decorators we are using nestjs-graphql where we don't use repository at all. I think it does it under the hood.
from typeorm-polymorphic.
Ah then I think it'll be a bit difficult as this package uses a custom repository to resolve the relatipnships
from typeorm-polymorphic.
Related Issues (20)
- Possible bug: polymorphic entity creation not working HOT 1
- Relation with property path ** in entity was not found HOT 3
- Entity type is always null when eager loading HOT 1
- Entity does not have a primary column. HOT 1
- Polymorphic Inheritance HOT 1
- Subject is undefined when working with soft-deleted entities. HOT 1
- Polymorphic from parent not work HOT 3
- The implementation in the readme is wrong. HOT 3
- How to get children of parent
- Where is version 0.0.10? HOT 1
- How to use in nestjs? HOT 4
- Children not populated when retrieving parent
- Property "media" was not found in "User". Make sure your query is correct.
- EntityMetadataNotFoundError: No metadata for "null" was found
- How to generate migration?
- use @PolymorophicRepository into entity.service.ts
- AbstractPolymorphicRepository.findPolymorphs uses wrong entityType HOT 2
- Update to work with newer TypeORM version HOT 1
- Creates N queries for hydrateMany HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-polymorphic.