Autoform and Relations using Transform - Update form not working

I use transform to have a reference between Stores and StoreTypes.

Stores = new Mongo.Collection('stores', {
  transform: function(doc) {
    doc.storetypesObj = StoreTypes.find({
      _id: { $in: doc.types }
    });

    return doc;
  }
});

and in my StoreTypes collection I use:

StoreTypes = new Mongo.Collection('storetypes', {
  transform: function(doc) {
    doc.storesObj = Stores.find({
      types: { $in: [ doc._id ] }
    });
    return doc;
  }
});

However this transform makes it impossible to update my Store using an update form like this:
{{> quickForm collection="Stores" id=updateStoreId type="update" doc=this}}

This will following exception:

Exception from Tracker recompute function:
meteor.js:880 RangeError: Maximum call stack size exceeded
    at Object.EJSON.clone (ejson.js:490)
    at ejson.js:529
    at Function._.each._.forEach (underscore.js:157)
    at Object.EJSON.clone (ejson.js:528)
    at ejson.js:529
    at Function._.each._.forEach (underscore.js:157)
    at Object.EJSON.clone (ejson.js:528)
    at ejson.js:529
    at Function._.each._.forEach (underscore.js:157)
    at Object.EJSON.clone (ejson.js:528)

If I remove the transform I am no longer able to display the properties of my referenced StoreTypes, but am able to update, so it definitely has to do with the transform function.

Insert forms work. Only Update forms a problem.
(If anyone knows a workaround for this those are definitely welcome too. )

Instead of using transform to handle your relationship, have you considered handling it via your publication instead with something like reywood:publish-composite? Check out the Guide’s recommendations for this approach.

1 Like

Had this same problem a while back and figured that it was the transform that was causing this problem. I set transform: null on each of the queries in my component code and that made it go away. Ended up running into this again last night. The idea of publish-composite sounds good but I’m gonna hold out for apollo since that would deprecate the pub/sub model in a way.

I do use transform as a way to mimic relationships, returning related objects in a single query so it’s been very helpful.