Giter Site home page Giter Site logo

Comments (3)

bashleigh avatar bashleigh commented on July 29, 2024

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.

s4kh avatar s4kh commented on July 29, 2024

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.

bashleigh avatar bashleigh commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.