Skip to content

Instantly share code, notes, and snippets.

@svasva
Created February 22, 2013 10:07
Show Gist options
  • Save svasva/5012259 to your computer and use it in GitHub Desktop.
Save svasva/5012259 to your computer and use it in GitHub Desktop.
Meteor publish-with-relations complex use
Meteor.publish('bike', function(id) {
return Meteor.publishWithRelations({
handle: this,
collection: Bikes,
filter: id,
mappings: [
{
key: 'userId',
options: { fields: config.users.publicFields },
collection: Meteor.users
}, {
reverse: true,
key: 'bikeId',
collection: Pictures
}, {
reverse: true,
key: 'bikeId',
collection: Comments,
options: {
sort: { createdAt: -1 }
},
mappings: [
{
key: 'userId',
collection: Meteor.users,
options: { fields: config.users.publicFields }
}
]
}, {
reverse: true,
key: 'bikeId',
collection: BikeParts,
mappings: [
{
key: 'partId',
collection: Parts,
mappings: [
{ key: 'typeId', collection: PartTypes },
{ key: 'vendorId', collection: PartVendors }
]
}, {
key: 'userId',
collection: Meteor.users,
options: { fields: config.users.publicFields }
}
]
}
]
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment