For a little bit of context: a Class
can have other Class
as Requirement
to be taken by a student. The Class
is taken by a Student
via a ClassGroup
which can be ordered in time with its attribute sessionYear
.
I want to put an OCL invariable constraint that will check if, for the sessionYear
a ClassGroup
, its Class
Requierement
were already taken before this sessionYear
.
in other words: sessionYear
for Requirement
< sessionYear
for Class
I tried a quite a few constaints and my closest attempt was this one:
context Etudiant inv C6: if ClassTaken->notEmpty then
classTaken->forAll(ct|ct.class.Requirement.OfferedGroup->collect(sessionYear)->forAll(sy| sy < cs.sessionYear))
else true endif
But the problem is, in the forAll(sy| sy->sy < cs.sessionYear)
, sy
won't be the Student
required ClassTaken
for a ClassGroup
, but rather a Bag with every instances of OfferedGroup
that are Requirement
for it.
I ended up doing this something like this: