Skip to main content
Version: Next


By default MikroORM will propagate all changes made to one side of bi-directional relations to the other side, keeping them in sync. This works for all relations, including M:1 and 1:1. As part of the discovery process, all M:1 and 1:1 properties are re-defined as getter/setter.

const author = new Author(...);
const book = new Book(...); = author;
console.log(author.books.contains(book)); // true

You can disable this behaviour via propagateToOneOwner option.

Propagation of Collection's add() and remove() operations#

When you use one of Collection.add() method, the item is added to given collection, and this action is also propagated to its counterpart.

// one to many
const author = new Author(...);
const book = new Book(...);
console.log(; // author will be set thanks to the propagation

For M:N this works in both ways, either from owning side, or from inverse side.

// many to many works both from owning side and from inverse side
const book = new Book(...);
const tag = new BookTag(...);
console.log(tag.books.contains(book)); // true
console.log(book.tags.contains(tag)); // true

Collections on both sides have to be initialized, otherwise propagation won't work.

Although this propagation works also for M:N inverse side, you should always use owning side to manipulate the collection.

Same applies for Collection.remove().

Last updated on by dependabot[bot]