barii
barii

Reputation: 345

CQRS (event sourcing) reading multiple aggregates

I have 2 aggregates, which have kind of 1-to-many relationsip. For example, I have a list of questions, and I want to add some of them to questonaires, some of them are mandatory and must be added to all questionaires, some of them are not, and the creator of the questionaire choses them.

Let's say I am using event sourcing and CQRS. I create the list of questions, and I want to add the mandatory questions to the questionaire. Normally I would do

questionaire.AssignQuestions(questions.Where(q => q.isMandatory).Select(q => q.Id))

something similar. But in CQRS I shouldn't use the query model for this. But in the command model I am using event store, so I would have to replay all events on all questions, and that doesn't seem to be reasonable.

Most probably my model is not event oriented enough, but I don't really have a better idea at this point. How should I model this?

thanks

Upvotes: 2

Views: 804

Answers (1)

rascio
rascio

Reputation: 9279

You command handler can query a read model to retrieve the list of the question ids to form the questionaire.

But in CQRS I shouldn't use the query model for this.

This is just a false myth

Upvotes: 1

Related Questions