meteor-collection-revisions icon indicating copy to clipboard operation
meteor-collection-revisions copied to clipboard

Uncaught TypeError: Cannot read property 'field' of undefined

Open ghost opened this issue 9 years ago • 11 comments

Bar changing a few var names I have implemented this awesome script as per the examples. The versions are recorded but I get an error on restore

Uncaught TypeError: Cannot read property 'field' of undefined

Template.recordRevisions.events({
  'click .revertRecord': function(e, t) {
    var foo;
    record = Template.parentData();
    //Meteor.call('restoreVersion', record._id, this.revisionId);
    CollectionRevisions.restore('Records', record._id, this.revisionId);
  }
});

I am attaching it like this

Records.attachCollectionRevisions();

ghost avatar Jul 13 '15 13:07 ghost

It looks as if it is having issues locating the revisions array. However, it is set to the default and is populating with versions.

ghost avatar Jul 13 '15 14:07 ghost

Is your Records.attachCollectionRevisions(); code in a place where both server and client can run it, or only client?

If its only available to the client and you are not publishing the revisions field, this would probably happen.

todda00 avatar Jul 13 '15 14:07 todda00

I have it in /lib beneath my collection information.

ghost avatar Jul 13 '15 14:07 ghost

can you add debug: true like this: Records.attachCollectionRevisions({debug:true}); and provide both server and client console logs?

todda00 avatar Jul 13 '15 14:07 todda00

=> Meteor server restarted I20150713-15:39:17.365(1)? collectionRevisions DEBUG: = Begin before.update I20150713-15:39:17.366(1)? collectionRevisions DEBUG: Defined options↓ I20150713-15:39:17.366(1)? { debug: true, I20150713-15:39:17.366(1)? field: 'revisions', I20150713-15:39:17.366(1)? lastModifiedField: 'lastModified', I20150713-15:39:17.366(1)? ignoreWithin: 0, I20150713-15:39:17.366(1)? ignoreWithinUnit: 'minutes', I20150713-15:39:17.366(1)? keep: -1 } I20150713-15:39:17.382(1)? collectionRevisions DEBUG: = Is past ignore window, c reating revision I20150713-15:39:17.382(1)? collectionRevisions DEBUG: Final Modifier↓ I20150713-15:39:17.382(1)? { '$set': I20150713-15:39:17.382(1)? { title: 'The East Dart River at Postbridge fgdfgd fg', I20150713-15:39:17.382(1)? da: 20, I20150713-15:39:17.382(1)? caption: '3569', I20150713-15:39:17.382(1)? text: 'This photograph was taken on 21/06/1935 l ooking north of the East Dart River near Postbridge.', I20150713-15:39:17.382(1)? tags: I20150713-15:39:17.382(1)? [ 'River', I20150713-15:39:17.382(1)? 'landscape', I20150713-15:39:17.382(1)? 'water', I20150713-15:39:17.382(1)? 'postbridge', I20150713-15:39:17.382(1)? 'river dart', I20150713-15:39:17.382(1)? 'moorland', I20150713-15:39:17.382(1)? 'geography' ], I20150713-15:39:17.382(1)? date: 1935, I20150713-15:39:17.382(1)? updatedBy: 'rzy7RJBQhSS5bxFcg', I20150713-15:39:17.382(1)? lastModified: Mon Jul 13 2015 15:39:17 GMT+0100 (GMT Daylight Time) }, I20150713-15:39:17.382(1)? '$unset': { notes: '', favouritedBy: '' }, I20150713-15:39:17.382(1)? '$push': { revisions: { '$each': [Object], '$positi on': 0 } } }

//When I click restore version nothing more appears in server console.

In clients I get.

ollectionRevisions DEBUG: = Begin before.update todda00_collection-revisions.js:124 collectionRevisions DEBUG: Defined options↓ todda00_collection-revisions.js:125 Objectdebug: truefield: "revisions"ignoreWithin: 0ignoreWithinUnit: "minutes"keep: -1lastModifiedField: "lastModified"proto: Object todda00_collection-revisions.js:127 collectionRevisions DEBUG: = Is past ignore window, creating revision todda00_collection-revisions.js:124 collectionRevisions DEBUG: Final Modifier↓ todda00_collection-revisions.js:125 Object$set: Objectcaption: "3569"da: 20date: 1935tags: Array[7]text: "This photograph was taken on 21/06/1935 looking north of the East Dart River near Postbridge."title: "The East Dart River at Postbridge fgdfgdfg"updatedBy: "rzy7RJBQhSS5bxFcg"proto: Object$unset: ObjectfavouritedBy: ""notes: ""proto: Object__proto__: Object todda00_collection-revisions.js:168 Uncaught TypeError: Cannot read property 'field' of undefined restoreRevision.coffee:18 Uncaught TypeError: Cannot read property 'field' of undefinedroot.CollectionRevisions.restore @ restoreRevision.coffee:18Template.recordRevisions.events.click .revertRecord @ record.js?7be9ce16998258fcff94dbf88b1387b250b2bac0:78(anonymous function) @ template.js:463Template._withTemplateInstanceFunc @ template.js:437(anonymous function) @ template.js:462(anonymous function) @ view.js:869Blaze._withCurrentView @ view.js:523(anonymous function) @ view.js:868(anonymous function) @ events.js:47jQuery.event.dispatch @ jquery.js:4665elemData.handle @ jquery.js:4333

ghost avatar Jul 13 '15 14:07 ghost

This is the part that is throwing the error.

revisionField = CollectionRevisions[collectionName].field

ghost avatar Jul 13 '15 14:07 ghost

I have the very same issue, is it solved yet?

Thanks

wvanooijen92 avatar Dec 09 '15 16:12 wvanooijen92

@latitudehopper @wvanooijen92 I'm having the same issue. Did you find a solution?

wceolin avatar May 03 '16 13:05 wceolin

I believe I ended up using Meteor Collection Hooks

wvanooijen92 avatar May 03 '16 14:05 wvanooijen92

@wvanooijen92 thanks, I'll have a look into it.

wceolin avatar May 04 '16 08:05 wceolin

I know this is old, but I created a pull request to fix it. I'll consider publishing my own library if the author is no longer maintaining this one. https://github.com/todda00/meteor-collection-revisions/pull/10

As a temporary workaround, you can set the collections field configured value:

CollectionRevisions.Foo = {
    field: 'revisions'
};
Foo.attachCollectionRevisions(CollectionRevisions.Foo);

nicklozon avatar Aug 13 '16 13:08 nicklozon