How to model relationship using event sourcing?

327 megtekintés
Ugrás az első olvasatlan üzenetre

Leo Zhang

olvasatlan,
2020. jún. 20. 17:34:402020. 06. 20.
– DDD/CQRS
In our scenario, we have a Course entity to represent course content. For each student attending a course, there is a CourseSession entity representing the learning progress of the student in the course. So there is a one-to-many relationship between Course and CourseSession. If using relational database, there will be a course table and course_session table, in which course has a unique ID and course session is uniquely identified by (courseId + studentId). We try to model this using event sourcing, and our event table is like following

------------------------------------------------------------------
| entity_type | entity_id | event_type | event_data |
------------------------------------------------------------------

this is fine for storing course, there is a courseId we can use as entity_id. But for CourseSession, there isn't an intrinsic id attribute, we have to use the concatenation of (courseId + studentId) as entity_id, which is not quite natural. Is there a better way to model this kind of relationship?

mynkow

olvasatlan,
2020. nov. 18. 2:00:252020. 11. 18.
– DDD/CQRS
Actually what you have suggested is how I do it all the time and it is very natural.

Usually I use URNs for identifiers. => https://tools.ietf.org/html/rfc5141

Here is an example:

CourseId => urn:boundedcontext:course:123
CourseSessionId  => urn:boundedcontext:course:123/student:456

Nils Kilden-Pedersen

olvasatlan,
2020. dec. 10. 9:54:032020. 12. 10.
– ddd...@googlegroups.com
Seems to me that CourseSession is just another entity (AR) which needs its own identifier, same as with Course and Student.

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dddcqrs/7878d9ef-b792-4045-8212-4fb79dccb5a2o%40googlegroups.com.
Válasz mindenkinek
Válasz a szerzőnek
Továbbítás
0 új üzenet