Book Image

Meteor Design Patterns

By : Marcelo Reyna
Book Image

Meteor Design Patterns

By: Marcelo Reyna

Overview of this book

Table of Contents (13 chapters)

Publishing with relations


We understand how our collections are related, but how can we make it easy to publish data with these relationships?

In Meteor, it can be problematic to publish relationships because of reactivity and the way publishers work. You would expect that by simply making two queries to two related collections and returning an array will publish a perfectly reactive collection. This is not the case. A Meteor.publish function does not rerun when dependencies change. This means that if a relationship is broken, the related document will remain published, or worse if a new relationship is made by another client, the related data will not publish.

To take care of database relationships and reactivity in Meteor, we use the lepozepo:publish-with-relations package. This package automatically takes care of subscribing to new data in the most efficient way possible when relationships are broken. If you are familiar with MySQL, this package makes JOINs a breeze.

Publishing products...