dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Calling Create Can Overwrite Return Values #563

Open jacobp100 opened 9 years ago

jacobp100 commented 9 years ago

I have an issue on StackOverflow that has the exact code I'm using. http://stackoverflow.com/questions/26451844/nodejs-possibly-not-scoping

The gist is that if I call model1.create a lot of times, the callback function gives the same element in every single function. In the example above, I would create an element, and then using that element, create attributes that reference the element's id. The result is that I would get all the elements created correctly, but the attributes all had the last element's id value, when they should in fact have individual values.

I was able to work around this by ensuring each create is finished before starting a new one, but that is a slow way to go about this, and is causing serious slowdown for my application.

Disabling cache does not fix the issue.

jamhall commented 9 years ago

I too have the same problem. Coud you please elaborate how you solved it by ensuring the create is finished? thanks!

jacobp100 commented 9 years ago

I had a function to generate an array of all the models I wanted to create, and used create with the array.