Hi Paul,

When you turn on the SQL adaptor debugging it will become clear what it is 
doing wrong. Then you’ll go “duh!"

It is probably one of those cases where the “joins” that get created don’t make 
sense in the full context of the query. It’s probably the Object-Relationional 
“impedance mismatch”

I have a little rule… never use “containsObject()” because it will fail on you 
in ways that are surprising… I made a vow, to only use ERXExistsQualifier 
instead of “OperatorContains.”

Here’s the full reason why:
http://www.chatnbike.com/presentation_existsQualifier/

So, here’s my recommendation:

1) Make your “Connection” entity have a single integer primary key. Do not have 
a compound PK.

2) Use ERXExistsQualifier.

It should do the trick :-)
AARON ROSENZWEIG / Chat 'n Bike
e:  [email protected]  t:  (301) 956-2319             
        

On Jan 28, 2015, at 8:54 PM, Paul Hoadley <[email protected]> wrote:

> 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!)
> 
> 
> -- 
> Paul Hoadley
> http://logicsquad.net/
> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/aaron%40chatnbike.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to