Lazy relations are not saved, DEFAULT added to insert queries
See original GitHub issueIssue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Saving a lazy relation does not read the id of the associated entity.
I have checked the tests and I cannot figure out whats wrong on my side. If I remove lazy relations, then everything is fine.
The issue is, I cannot remove it everywhere. I know its an anti-pattern but some relations are resolved dynamically on specific events to avoid unnecessary load.
I have a Feed
entity with Promise<User>
ManyToOne
& OneToMany
relations. Both side uses Promise.
@Entity()
class Feed {
@ManyToOne(t => User, u => u.feeds)
@JoinColumn({ name: 'user_id', referencedColumnName: 'id' })
user: Promise<User>;
@RelationId((f: Feed) => f.user)
userId: string;
}
@Entity()
class User {
@OneToMany(t => Feed, f => f.user)
@JoinColumn({ name: 'id', referencedColumnName: 'user_id' })
feeds: Promise<Feed[]>;
}
const user = await connection.getRepository(User).findOneOrFail(id);
const feed = new Feed();
feed.user = Promise.resolve(user);
await connection.getRepository(Feed).save(feed);
// query: INSERT INTO `feed`(`user_id`) VALUES (DEFAULT)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top GitHub Comments
Is there any solution?
Is there any workaround for this issue?