0

I have an association between Person and Department, and I want to check if Person.function is unique

Person.allInstances->isUnique(function)

but I want to check if function is unique for Persons in the same department and not between all persons. I can have the same function but not in the same department. I don't know how to use isUnique for each department (Persons group by department).

1 Answers1

0

If you have a scope for which isUnique is to apply then gather that scope as the source. Perhaps as department.persons->isUnique(function). (This is exactly the approach that you should apply anyway to avoid using the generally over-powerful and inefficient allInstances() wherever possible.)

Ed Willink
  • 1,205
  • 7
  • 8