svasva / meteor-publish-with-relations

Meteor.js SmartPackage to publish associated collections at once.
162 stars 30 forks source link

Simple USE Case: Example #6

Closed wbashir closed 11 years ago

wbashir commented 11 years ago

I am having somewhat of a difficult time using this package with a simple use case

I have two meteor collections Users & Tickets and i would like to retrieve certain users (using a filter ) and then retrieve the latest date on my Ticket Collection.

Ticket: "due_date", Ticket has a due date and i would like to just get the latest ticket with the earliest due date for that user publish along.


 Meteor.publish('trainees', function(id) {
    Meteor.publishWithRelations({
      handle: this,
      collection: Users,
      filter: id,
      mappings: [{
        key: 'owner',
        collection: Lessons,
        filter: { due_date: closest to today }
      }]
    });
  });

Any guidance on doing something like this would be really helpful

svasva commented 11 years ago

In this case I guess you want to use something like options: { sort: { due_date: -1 }, limit: 5 } at the owner mapping to get five most recent lessons.