Giter Club home page Giter Club logo

Comments (5)

silicakes avatar silicakes commented on May 27, 2024 2

This is related to typeORM itself: typeorm/typeorm#2276 and will probably be resolved in due time.
The thing about Promise.resolve, is that it also returns a promise so essentially you're assigning a promise object, rather than its value.

In theory, you could have assigned the resolved value, but then typescript will fail as it expects a promise, so it's sort of a double bind where declaring a promise expects lazy evaluation, but the entities themselves don't handle it and still expect the actual value when assigning their relational entities.

For now, you can define your entities like this:

@Entity()
class User {
  @OneToOne('Profile', 'user', { lazy: true })
  profile: Profile
}

and await for the relation like this: object.user = await object.user;
or this:

const user = await object.user;
object.user = user;

The bad part here is that the types don't really represent the proper values, i.e Profile is actually Promise<Profile> with the lazy flag on.
However, at least for now, this will enable you to pass values to your entities while still loading it lazily.

from typeorm-fixtures.

mehdibo avatar mehdibo commented on May 27, 2024 1

Hello
I am still facing this issue, any solution?

from typeorm-fixtures.

ygarris avatar ygarris commented on May 27, 2024

Hey @RobinCK ,
I tried to find a workaround by using processors, but it's not working, too.

account.yaml:

entity: Account
processor: processors/account.processor.ts
items:
  account1:
    app: test_app
    roles:
      - user
    user: '@user1'

processors/account.processor.ts:

import { IProcessor } from 'typeorm-fixtures-cli/dist';
import { Account } from '../../src/account';

export default class AccountProcessor implements IProcessor<Account>{
  preProcess(name: string, object: Account): any {
    object.user = Promise.resolve(object.user);
    return object;
  }
}

Account table still has userId set to null.

from typeorm-fixtures.

ygarris avatar ygarris commented on May 27, 2024

Hey @RobinCK
did you had a chance to take a look at this issue?
probably there is no good fix, but rather some workaround you can imagine?

from typeorm-fixtures.

nmacherey avatar nmacherey commented on May 27, 2024

Dear all its a limitation of typeorm but it has to be solved also by the promise loader.

The main limitation is due to the class-transformer package which transforms promises in property names like __promise_<property>__ and results in a bad typeorm interpretation. It is used is in the Builder.js package.

I proposed a solution there:

#159

Regards

from typeorm-fixtures.

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.