Lepozepo / meteor-publish-with-relations

Meteor.js SmartPackage to publish associated collections at once.
https://atmospherejs.com/lepozepo/publish-with-relations
11 stars 4 forks source link

Published data returns ID for the related field #9

Open ebertulfo opened 8 years ago

ebertulfo commented 8 years ago

Hi!

I have this code:

Meteor.publish('leagues', function(){ this.relations({ collection: Leagues, filter: {"abbrev": "test"}, mappings: [ { foreign_key: "sport", collection: Sports } ] }) this.ready(); // return Leagues.find({}); });

for the following collections:

Leagues

Sport

On subscription, the published data returns ID for Leagues.sport instead of the mapping above. What am I doing wrong?

jflecool2 commented 8 years ago

Misunderstood what this package do. The single purpose of this package is to publish linked data at the same time so you don't have to go back-and-forth subscribing to linked data. If you have a top-10 posts subscription, you can bundle their author at the same time, with no fuss. If you subscribe to "top10posts" both Posts.find() and User.find() will be populated. This is 'all' this package does. It will not alter the League object so sports stop having an id but an Sport object instead. It will only populate Sport client-side db so your app can do Sports.findOne({_id:this.sport}).name

To understand the problem it attempts to get rid of, take a look at this page: https://www.discovermeteor.com/blog/reactive-joins-in-meteor/

Lepozepo commented 8 years ago

If you want to build a relationship method that is attached to the object, I strongly recommend using astronomy. This package will only handle publishing data (and keeping it reactive in an efficient way), there are no transformations.

ebertulfo commented 8 years ago

Thanks a lot for clearing things up guys! I hope we can have more active guys in the community like you to help out beginners like me. Google might be enough but having direct guidance is a lot more helpful. Thanks again!