New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with updating parent in Lazy relationships #2729
Comments
I've done a fair bit of investigation on this on @cuzzea's StackOverflow question about this issue, and tracked it down to The OP experiences this issue because TypeORM's This can be most easily be replicated using the following test case: entity/a.ts:@Entity()
export class A {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@OneToOne(() => B, b => b.a)
@JoinColumn()
public b: Promise<B>;
} entity/b.ts@Entity()
export class B {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@OneToOne(() => A, a => a.b)
public a: Promise<A>;
} index.tscreateConnection().then(async connection => {
...
const a = aRepo.create({ name: "foo", b: Promise.resolve() });
await aRepo.save(a);
}); The I'll add a pull request with the above tests shortly. |
I've created the following test for this issue: https://github.com/afurculita/typeorm/commit/977f87549b04d0754b1a100c51ad3e32ab6f9b94 and it works in the form used in the test. The following queries are produced during this test:
The following changes have been made to the entities
Now, one more important thing is how you run your application or the tests. If you use |
@cuzzea can this issue be closed? Are you still having the problem from the issue? |
For those finding there way here who are looking for a workaround in lieu of #2902 being merged, i think i've figured something out (assuming you're using the ActiveRecord pattern with typeorm). First to summarize, as most of this information is absent from documentation and needs to be pieced together from various issues: As pointed out in this thread, when using
What this means is that with the
What this does is define an overridden version of this Note: I haven't handled the type signature for |
Nice summary and excellent solution for the problem of assigning object literals @JemarJones! Given it appears unlikely that #2902 will be merged, perhaps a PR integrating your |
Issue type:
[x] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
Hey, I am not sure if this is a bug, or I am doing something wrong, but I tried a lot of things to get this working and I couldn't. I hope you guys can help.
Basically I have a one to one relationship that I need to lazyLoad. The relation tree is kind of big in my project and I can't load it without promises.
The issue I face is that when I save a child, the parent update generated sql is missing the update fields:
UPDATE `a` SET WHERE `id` = 1
This is working perfectly when I am not using lazyLoading (Promises).
I got a simple example set up using the generated code tool.
Entity A
Entity B
main.ts
Output
If I remove the promises from the entities, everything is working fine:
Entity A
Entity B
main.ts
Output
I have also created a git project to illustrate this and for easy of testing.
The text was updated successfully, but these errors were encountered: