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

Specify which fields of a document to pull into the before/after update hooks

Open znewsham opened this issue 6 years ago • 7 comments

This PR makes two changes:

  1. A bug fix: If you define any after hooks, the before hook will fetch the previous document, even if fetchPrevious is set to false.
  2. A new feature allowing you to specify which fields of a document should be pulled in if fetchPrevious is true

for (2) you can either specify the fields as globals or on a specific aspect as follows:

  Collection.hookOptions.after.update = { fetchFields: { _id: 1, field1: 1, field2: 1, field3: 1 } };

By default you get all fields (so the default behaviour has not changed)

The tests all pass, however another set of eyes would be useful!

znewsham avatar Oct 21 '19 16:10 znewsham

@znewsham Hello and thank you for your contribution! I have merged modernization PR so there will be some conflicts, but those should be easy to resolve.

StorytellerCZ avatar Oct 21 '19 18:10 StorytellerCZ

I've manually fixed the conflicts for this, but we now have failing tests due to the absence of jQuery in 1.8.3. Is there a way to configure which npm packages are installed before tests are run?

copleykj avatar Jan 12 '20 17:01 copleykj

Yes, you can use the --test-app-path ./path/to/test-app argument to a directory containing a package.json file. Here's an example how we did it for blaze https://github.com/meteor/blaze/commit/f13c2ad979fb56cd3160f105eb5b9a7d61b8ef43

sebakerckhof avatar Jan 13 '20 02:01 sebakerckhof

Awesome, thanks @sebakerckhof

copleykj avatar Jan 13 '20 02:01 copleykj

@StorytellerCZ could you take a look at the failing tests and see if you can get them to pass? I've not been able to manage it.

copleykj avatar Feb 21 '20 03:02 copleykj

@copleykj I'll see if I can get some time on this over the weekend.

StorytellerCZ avatar Feb 21 '20 08:02 StorytellerCZ

@copleykj Looks like an issue with spacejam, when running tiny test on its own the test pass.

StorytellerCZ avatar Mar 08 '20 06:03 StorytellerCZ