I mean:

Rather than saying this.getToMany() you can say EOFetchSpecification (other, inverseToOne = this, null)

public static String inverseRelationshipNameForRelationshipNameAndEntityName(
                String relationshipName,
                String entityName)
        {

                EOEntity entity = 
EOModelGroup.defaultGroup().entityNamed(entityName);

EORelationship relationship = entity.relationshipNamed (relationshipName);

EORelationship inverseRelationship = relationship.inverseRelationship();

                return inverseRelationship.name();

        }

public static EOFetchSpecification fetchSpecificationForRelationshipWithKey(
                EOEnterpriseObject anObject,
                String aKey)
        {
                if (anObject != null)
                        anObject.willRead();
                if (anObject == null || aKey == null)
                        return null;
                anObject.willRead();
                String anEntityName = anObject.entityName();
EOEntity anEntity = EOModelGroup.defaultGroup().entityNamed (anEntityName);
                EORelationship aRelationship = anEntity.relationshipNamed(aKey);
                if (aRelationship == null)
                        return null;
                EOEditingContext anEditingContext = anObject.editingContext();
                EOGlobalID aGlobalID = 
anEditingContext.globalIDForObject(anObject);
                String aModelName = anEntity.model().name();
                EODatabaseContext aDatabaseContext =
EOUtilities.databaseContextForModelNamed(anEditingContext, aModelName);
                aDatabaseContext.lock();
                NSDictionary row = 
aDatabaseContext.snapshotForGlobalID(aGlobalID);
                aDatabaseContext.unlock();
                if (row == null)
                        return null;
                EOQualifier aQualifier = 
aRelationship.qualifierWithSourceRow(row);
                if (aQualifier == null)
                        return null;
                EOEntity aDestinationEntity = aRelationship.destinationEntity();
                String aDestinationEntityName = aDestinationEntity.name();
                EOFetchSpecification fetchSpec =
                        new EOFetchSpecification(aDestinationEntityName, 
aQualifier, null);
                fetchSpec.setIsDeep(aDestinationEntity.isAbstractEntity());
                cat.debug("fetchSpec = " + fetchSpec);
                return fetchSpec;
        }

On Aug 16, 2007, at 11:00 PM, Paolo Sommaruga wrote:

Hi Pierre,

please,

Il giorno 16/ago/07, alle ore 19:18, Pierre Bernard ha scritto:

[...]
- just fetch required object regarding mentioned relationship as just one
of attributes involved

A to-many is always the inverse of a to-one. You could qualify objects using that to-one.

how one can you "qualify objects using that to-one" ? Can you explain a little more ?

Regards

Paolo Sommaruga


I have done this on relationships having 300000-500000 objects. For 100 it is overkill in both code to write and IO accesses.

- index that array converting it into actual multi-dimensional as
mentioned above (using pure Java multidimensional arrays or nesting
NSArrays/NSDictionaries)

I would recommend this if you need to get multiple objects from the same relationship or if you repeatedly need to get to the object. There is no point in scanning the array over and again.

You can listen to EOF notifications to see when your cache goes stale.

Pierre



- - -
Houdah Software s. à r. l.
http://www.houdah.com

HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
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