Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating query with multiple joins #16

Open
enzolutions opened this issue Oct 25, 2017 · 3 comments
Open

Error generating query with multiple joins #16

enzolutions opened this issue Oct 25, 2017 · 3 comments

Comments

@enzolutions
Copy link

I am trying to do a query with 2 and more joins, the problem I found is I when I load my router directly works, but when I jump from a router menu doesn't work.

I don't know if is an issue with react-route 2.x or react-router-dom 4.x i tried with both with same behavior.

Here the code I am trying

Actions.join(Customers, "customerId", "customer", ["_id", "firstname","lastname"]);
Actions.join(ActionTypes, "actionTypeId", "type", ["name"]);

if (Meteor.isServer) {
    // This code only runs on the server
    Meteor.publish('actions', function actionsPublication() {
        // Get current customers
        var cursor = Actions.find({});
        return Actions.publishJoinedCursors(cursor);
    });
}

Maybe onely one join is possible?

@enzolutions
Copy link
Author

Looks like is all about timing

My Solution (ugly but works)

I removed two joins and leave only one join and after call the subscribe I traverse the results to attach the extra info, but validating that the subscriptions are ready.

  Meteor.subscribe('actions');
  const logsSubscribe = Meteor.subscribe('logs');
  const actionsTypesSubscribe = Meteor.subscribe('actionTypes');

  const data = [];

  let actions = Actions.find().fetch();

  if(logsSubscribe.ready() && actionsTypesSubscribe.ready()) {
      _.each(actions, function (action, name) {
          var log = Logs.findOne({_id: action.logId});
          var type = ActionTypes.findOne({_id: action.actionTypeId});
          data.push({
              key: action._id,
              date: action.actionDate,
              time: action.actionTime,
              customer: action.customer.firstname + ' ' + action.customer.lastname,
              customerId: action.customer._id,
              status: action.status,
              type: type.name,
              notes: log.notes,
              files: log.files

          });
      });
  }

Maybe you could document and include a new feature that warranty that the subscriptions are ready.

@leite08
Copy link

leite08 commented Jan 13, 2018

Hi @enzolutions! I've used a code very similar to yours...

Actions.join(Customers, "customerId", "customer", ["_id", "firstname","lastname"]);
Actions.join(ActionTypes, "actionTypeId", "type", ["name"]);

.. and it works for me.

Have you tried it with the latest version?

@enzolutions
Copy link
Author

Not really, but I switched to Mongo Aggregations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants