A long day, and my brain is not computing this one. Either it is obvious and I cannot see it, or my solution at the end is one of a number of complicated ways to do the non-obvious .... either way, someone here probably has seen this before.

I had to do some refactoring and kill one side of a toMany that was just getting too big to have anymore.

The last artifact I have left is an EOQualifier for a two-hop keyPath and my brain is just not giving it to me if it is obvious


1) Before I got rid of one side of the huge relationship I had this:

CTMediaTemplate <-->> CTMessage <<--> CTJob

2) After refactoring out the toMany of the first entity shown above to the second entity, I have this:

CTMediaTemplate <----- CTMessage <<--> CTJob

The problem: I had a method in CTJob that returned a fetch spec for the CTMediaTemplate.

public ERXFetchSpecification<CTMediaTemplate> fetchSpecificationForMediaTemplates() { EOQualifier q = CTMediaTemplate.XKEY_MESSAGES.append(CTMessage.XKEY_JOB).eq(this); ERXFetchSpecification<CTMediaTemplate> fs = new ERXFetchSpecification<CTMediaTemplate>(CTMediaTemplate.ENTITY_NAME, q, null,true,false,null);
        return fs;
    }

FYI, the qualifier translated into normal plain WO would be sth like this: q = new EOKeyValueQualifier( "messages.job", EOQualifier.QualifierOperatorEquals, this );

So my "messages" relationship from CTMediaTemplate to CTMessage is now gone and so cannot be used in the qualifier keypath. How do I qualify the CTMediaTemplate objects now without that part of the keypath?

My (possibly overkill) solution I was thinking of was actually creating a flattened toMany (which feels dirty) in the EOModel like this

CTMediaTemplate <<-------(flattened relationship in CTJob: "mediaTemplates" = "messages.mediaTemplate") -------- CTJob

... just so I could do something like the following in a CTJob instance to create the qualifier using EORelationship.qualifierWithSourceRow(...) ..... but it seems like there might be an easier way that I am not seeing that would avoid me needing to create that flattened toMany from CTJob to CTMediaTemplate which feels sloppy .... any suggestions?

<snip>
        String aKey = "mediaTemplates";
        this.willRead();
        EOEntity anEntity = entity();
EORelationship aRelationship = anEntity.relationshipNamed(aKey);
        EOEditingContext anEditingContext = this.editingContext();
EOGlobalID aGlobalID = anEditingContext.globalIDForObject(this);
        String aModelName = anEntity.model().name();
EODatabaseContext aDatabaseContext = EOUtilities.databaseContextForModelNamed(anEditingContext,
                aModelName);
        NSDictionary aRow  = null;
        aDatabaseContext.lock();
        try {
                aRow = aDatabaseContext.snapshotForGlobalID(aGlobalID);
        } finally {
                aDatabaseContext.unlock();
        }

        EOQualifier q = aRelationship.qualifierWithSourceRow(aRow);
</snip>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to