Skip to content

Relation decorators: allow to pass string instead of typeFunction #4190

Closed
@haschu

Description

@haschu

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue


To define table relations using decorators, this is the current way:

Photo.ts

    @ManyToOne(type => User, user => user.photos)
    user: User;

User.ts

    @OneToMany(type => Photo, photo => photo.user)
    photos: Photo[];

This works fine on Node.js, but can cause circular dependency issues on the frontend side (e.g. when using Angular CLI). See: #2059 or #1290

We could overcome those issues, if the following would be possible:

Photo.ts

    @ManyToOne('User', 'photos')
    user: User;

User.ts

    @OneToMany('Photo', 'user')
    photos: Photo[];

This should be fairly easy to implement, as it turns out that TypeORM already supports string instead of types (e.g. when using EntitySchema) - the only thing to do is to adjust the typeFunction type of the decorator functions.

@pleerock If that feature would be ok I could post a PR :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions