thenativeweb / node-cqrs-eventdenormalizer

Node-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern. It can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.
http://cqrs.js.org/pages/eventdenormalizer.html
MIT License
38 stars 27 forks source link

Possible to query another collection while denormalizing? #20

Closed TomKaltz closed 8 years ago

adrai commented 9 years ago

Yes, see: https://github.com/adrai/node-cqrs-eventdenormalizer/issues/5

TomKaltz commented 9 years ago

Ah. I did some experimentation and found that get is not a function on the returned collection but is part of the repository object of the collection. I've updated the example from #5 below...

module.exports = require('cqrs-eventdenormalizer').defineViewBuilder({
  name: 'enteredNewPerson',
  aggregate: 'person',
  context: 'hr',
  version: 2,
  id: 'aggregate.id',
  payload: 'payload'
}, function (data, vm, callback) {
  vm.set('firstname', data.firstname);
  vm.set('lastname', data.lastname);

  var portfolioCol = require('../portfolio/collection');
  portfolioCol.repository.get(evt.payload.portfolioId, function (err, portfolio) {
    //error handling
    //vm.set...
    //vm.set...
    callback(null);
  });
});

@adrai can you please confirm I'm on the right track?

adrai commented 9 years ago

Try:

portfolioCol.loadViewModel(...

Il giorno 2-lug-2015, alle ore 23:27, Thomas Kaltz III notifications@github.com<mailto:notifications@github.com> ha scritto:

Ah. I did some experimentation and found that get is not a function on the returned collection but is part of the repository object of the collection. I've updated the example from #5https://github.com/adrai/node-cqrs-eventdenormalizer/issues/5 below...

module.exports = require('cqrs-eventdenormalizer').defineViewBuilder({ name: 'enteredNewPerson', aggregate: 'person', context: 'hr', version: 2, id: 'aggregate.id', payload: 'payload' }, function (data, vm, callback) { vm.set('firstname', data.firstname); vm.set('lastname', data.lastname);

var portfolioCol = require('../portfolio/collection'); portfolioCol.repository.get(evt.payload.portfolioId, function (err, portfolio) { //error handling //vm.set... //vm.set... callback(null); }); });

@adraihttps://github.com/adrai can you please confirm I'm on the right track?

Reply to this email directly or view it on GitHubhttps://github.com/adrai/node-cqrs-eventdenormalizer/issues/20#issuecomment-118176080.