Comments (5)
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.
Hello
I am still facing this issue, any solution?
from typeorm-fixtures.
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.
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.
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:
Regards
from typeorm-fixtures.
Related Issues (20)
- [Bug] Lodash dependency pin
- [Bug] Postgres 'timestamptz' column failing at parsing long date HOT 4
- [Feature request] Add support for typeorm ^0.3.0 HOT 18
- [Bug] Update dependencies HOT 2
- [Bug] $current not working on array fields
- [Bug] class-validator entities may be incorrectly "unserialized/initialized" HOT 1
- [Bug] HOT 2
- [Bug] fix faker deprecation warning
- [Bug] Null ID when referencing another fixture HOT 1
- [Bug] glob is broken in Windows and cannot iterate by folder HOT 2
- [Feature request] Add support for regular expressions/glob patterns when setting fixtures location HOT 1
- [Bug]
- [Feature request] Add TsLoader for fixture
- Problem with @Exclude HOT 2
- [Feature request] Add faker examples with parameters in README
- [Feature request] Reference one field to generate another
- [Feature request] access to entity name in processor HOT 2
- [Feature request] Replace class-transformer usage with TypeORM Repository#merge
- [Bug] Limit faker version HOT 1
- [Feature request] Update `reflect-metadata` dependency to 0.2.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-fixtures.