Skip to content

Instantly share code, notes, and snippets.

@B4nan
Created February 6, 2022 01:44
Show Gist options
  • Save B4nan/003fedc741a4ae4243fc06696aabc4d6 to your computer and use it in GitHub Desktop.
Save B4nan/003fedc741a4ae4243fc06696aabc4d6 to your computer and use it in GitHub Desktop.
// first partially load author entities
const r1 = await em.find(Author, {}, { fields: ['id'] });
r1[0].email = 'lol'; // let's change one of the emails
console.log(r1[0].name); // undefined, not loaded
// reload full entities - no `refresh: true` needed!
const r2 = await em.find(Author, {});
console.log(r2[0]); // fully loaded author entity, but `email` is changed to 'lol'
console.log(r1[0] === r2[0]); // true, same entity instance, just updated!
// flushing will now fire one update query to change the email of one author
await em.flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment