I'm trying to find an OCL excpression (calculator), but I'm not sure how to get the sum of the attributes of a collection.
I have a class Customer
and a class Orders
. I want to have the sum of all orders of a particular year saved in the Customer
class, attribute revenue
.
Orders
has attributes 'date_order' and 'amount'.
Given is that year(Date) gives the year of a specific date and Date.now()
gives the current date.
I found this solution:
context Customer::revenue
derive: self.orders -> select(year(datum_order) = (year(Date.now()) – 1)) -> collect(amount) -> sum()
I would like to not use collect, but I really don't know how to do this with only the select statement. I assume leaving out collect(amount) and change sum to amount.sum()
is also not right?
I hope someone can help me with this expression.