perak / meteor-joins

Collection joins for Meteor
77 stars 7 forks source link

Deep architecture #21

Open jonathanroze opened 6 years ago

jonathanroze commented 6 years ago

Hi,

I've some trouble to use this package !

I have 3 collections :

Configurations:

Prizes:

Games:

When I try to join a configuration with Games it works well but the Prize is not resolved in configurations!

Do you have any tips to achieve this?

Thanks :)

perak commented 6 years ago

@Clowning

Are you trying to publish games, and you have configuration in it, but inside that configuration you expect prize? - not sure is that possible (typing from phone, need to focus on code to answer), but try to publish and subscribe to all prizes just to check if that helps (would it appear inside configuration which is inside game)

jonathanroze commented 6 years ago

Hi Perak, thanks for your reactivity :-) !

Yes it's defined in both scope!

Yes i tried both way !

It's working well to resolve Configurations but Configurations doesn't resolve Prizes!

Here my code:

Configurations.js

export const Configurations = new Mongo.Collection('Configurations');

if (Meteor.isServer) {
    // This code only runs on the server
    Meteor.publish('Configurations', function () {
        const cursor = Configurations.find({})

        return Configurations.publishJoinedCursors(cursor); // instead of simply returning resulting cursor
    });
}

Configurations.join(Prizes, "prizeId", "prize", []);

Games.js

export const Games = new Mongo.Collection('Games');

if (Meteor.isServer) {
    // This code only runs on the server
    Meteor.publish('Games.getLast', function (limit) {
       const cursor = Games.find({})

       return Games.publishJoinedCursors(cursor); // instead of simply returning resulting cursor
    });

    Meteor.publish("Games.total", function () {
        return BettingGrids.find({}, {fields: {_id: 1}})
    });
}

Games.join(Configurations, "configurationId", "configurations", []);

Yeah right!

My expected result is that:

One Game

{
  "_id": 13434,
  ...
  "configuration": {
    "_id": 22323,
    "name": "Basic configuration",
     ...
    "prize": {
      "_id": 34239,
      "name": "Smartphone"
      ...
    }
  }
}