delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

transform doesn't work #75

Closed romaluca closed 8 years ago

romaluca commented 8 years ago

Hi, i have a collection defined like this:

Actions = new Mongo.Collection("actions", { transform: function (doc) {
  if (doc.photoId) {
    doc.photo = Photos.findOne(doc.photoId, {
      fields: {
        _id: 1, position: 1, commentsCount: 1,
        votesCount: 1, votedBy: {$elemMatch: {$eq: userId}},
        uploaded: 1, createdAt: 1, user: 1, contest: 1
      }
    });
  }
}});

In android in the onDataAdded method i receive the parameter of action but without the parameters of Photo. How i can do? Thanks

ocram commented 8 years ago

Thanks for your question!

As far as I know, using the onDataXxx callbacks, you always get what is actually in the MongoDB collections. And since the transformation is not actually in the database, you don't get that.

The transformation is only in the scope of your JavaScript business logic. I don't think you can get this on Android without changing the actual database contents. Sorry!

Does this help?

romaluca commented 8 years ago
Meteor.publish("actions", function (id, isNext) {
  actions = Actions.find(where, {sort: sort, limit: LIMIT });      
  photoIds = _.compact(_.uniq(actions.map(function(a){ return a.photoId })));
  photos = Photos.find({ _id: { $in: photoIds } }, { fields: {
        _id: 1, position: 1, commentsCount: 1,
        votesCount: 1, votedBy:{$elemMatch: { $eq: userId }},
        uploaded: 1, createdAt: 1, user: 1
      } });

  return [actions, photos];
});

Thanks for the answer. Now i return an array of cursors. The problem is the elements of actions maybe arrive before the photo's elements. So when an action arrives i can't show it because the photo of the action is not arrived yet. So i think i have to memorize all data in a database and show them only when are complete. Have you any better solutions?

Thanks!

ocram commented 8 years ago

@romaluca Thanks for updating your solution!

If you need database access to store data temporarily, please take a look at this upcoming feature: https://github.com/delight-im/Android-DDP/issues/54 You can use it already today.

And if you need to know when all photos have been received, you may use the SubscribeListener in combination with the subscribe method, as explained here: https://github.com/delight-im/Android-DDP/issues/65

Is this of any help?

romaluca commented 8 years ago

Thanks!