Hello,
I have two entities in a model: Teacher and School. There is a many-to-many relationship between Teacher and School, represented as Connection, a join entity. So, Teacher and School both have a 'connections' relationship, and Connection has both 'teacher' and 'school'. There are no flattened relationships. The Connection entity is modelled as a first class EO, as it contains other useful metadata.
Say I have a School S. I want a list of "unconnected Teachers" for S such that any Teacher T in that list has no Connection C in T.connections() such that C.school() returns S. This method in School produces the result I'm after:
public NSArray<Teacher> unconnectedTeachers() { NSArray<Teacher> connectedTeachers = (NSArray<Teacher>) connections() .valueForKey(Connection.TEACHER_KEY); NSArray<Teacher> allTeachers = Teacher .fetchAllTeachers(editingContext()); return ERXArrayUtilities .arrayMinusArray(allTeachers, connectedTeachers); }
But surely this is achievable with a single qualifier on Teacher? I tried this:
ERXQ.not(Teacher.CONNECTIONS.dot(Connection.SCHOOL).containsObject(this))
This looked promising in WOUnit testing, but fails to return the "unconnected Teachers" against an actual database. Does anyone have any suggestions? (Looking at you Dave A and Aaron!)
|