• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Qualifier involving many-to-many relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Qualifier involving many-to-many relationship


  • Subject: Re: Qualifier involving many-to-many relationship
  • From: Aaron Rosenzweig <email@hidden>
  • Date: Wed, 28 Jan 2015 22:34:01 -0500

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@hidden  t:  (301) 956-2319
Chat 'n Bike Chat 'n Bike

On Jan 28, 2015, at 8:54 PM, Paul Hoadley <email@hidden> 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@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Qualifier involving many-to-many relationship
      • From: Paul Hoadley <email@hidden>
References: 
 >Qualifier involving many-to-many relationship (From: Paul Hoadley <email@hidden>)

  • Prev by Date: Qualifier involving many-to-many relationship
  • Next by Date: Re: Qualifier involving many-to-many relationship
  • Previous by thread: Qualifier involving many-to-many relationship
  • Next by thread: Re: Qualifier involving many-to-many relationship
  • Index(es):
    • Date
    • Thread