How do you model the following restriction?
A place is popular if it has been bookmarked by 2 or more than 2 users.
Here the corresponding uml diagram:
I tried several ways, for example:
context place inv: place.popular = (self.user.place.popular>=2)
but nothing worked well...

The constraint that you expressed is an interesting start but does not work because
self.userin theplacecontext is a collection. Your expression moreover attempts to use popular as if it were an integer.If there would be an unambiguous
user, you’d just need to check itssize():Unfortunately, there are two associations with
User: one for thefavorites(bookmarks) and for forhistoric(past visits whether they appreciated or not). This makes that expression ambiguous. To disambiguate, in absence of a role name (name at the association end), you’ll need to qualify theuserwith the association name:(Btw, in case of absence of association name, you'd need to use the default name
A_place_userinstead offavorites).See also section 7.5.3 of the OCL specifications for more information about navigating associations.
Edit: more complex navigations**:
You could also navigate to properties of associated classes. It works like the navigation above, but with the help of the
collect()operation. You can then perform collection oprations such assum()Navigating to a specific object in a collection of linked objects is more delicate. In the case of the steps, we see that the association is ordered (by the way, it should be
{ordered}and not«ordered»). This allows to uselast()to get the last element in the given order: