• 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: Child EditingContext and fetches
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Child EditingContext and fetches


  • Subject: Re: Child EditingContext and fetches
  • From: Fabrice Pipart <email@hidden>
  • Date: Wed, 22 Mar 2006 12:44:42 +0100

Hi !


On Mar 22, 2006, at 12:21 AM, Lachlan Deck wrote:

Hi there,

On 21/03/2006, at 8:31 PM, Fabrice Pipart wrote:

I have a question that seems simple but I did not find any accurate information on this...
Is it possible to fetch EOs the following way :

childEc = new EOEditingContext(session().defaultEditingContext());
EOUtilities.createAndInsertInstance(childEc, "Day");
childEc.saveChanges();
EOFetchSpecification fs = new EOFetchSpecification("Day", qual, null);
NSArray days = childEc.objectsWithFetchSpecification(fs);

Should I be able to fetch the objects?
In my case it does not work.
It only works if I do a saveChanges on the parent ec (when then objects are really written in database), which of course I do not want to do.

Is this normal?

As Ken mentioned, this is normal. But here's the easy way to get what you want...

Hmmm
I don't really understand what it should do...


EOEditingContext childEc;
NSMutableSet days;
EOFetchSpecification fs;
EOQualifier qual; // assume exists

childEc = new EOEditingContext(session().defaultEditingContext());
days = new NSMutableSet();

Do you mean I can keep a reference on those "Day" objects?
I am already doing it, OK.


days.addObject(EOUtilities.createAndInsertInstance(childEc, "Day"));

fs = new EOFetchSpecification("Day", qual, null);
days.addObjectsFromArray(childEc.objectsWithFetchSpecification(fs));

If I don't misundertand,
childEc.objectsWithFetchSpecification(fs)
should return null since there is no difference with what I proposed...


try {
childEc.saveChanges();
parentEc.saveChanges();
} catch(...) {

}

Is there a way to fetch those objects anyway? or I should just keep an array of them and look for the EO I am looking for in a "for" loop ?

To find the object you're looking for you have the option of using an in-memory EOQualifier operation. e.g., EOQualifier.filteredArrayFromQualifier(days.allObjects(), qual);

YES !
I knew it existed but forgot that... that was what I was looking for !
It will allow me to use the qualifiers I have and work in memory since I cannot work in database :-)
I suppose that in term of performance, it is faster than a for loop.

The above approach would be better (as it'll find all objects satisfying the qualifier), but, if you're certain there's no duplicates, another option would be to use something like:
NSArray eoDays = days.allObjects();
int index = ((NSArray)eoDays.valueForKey("name")).indexOfObject("Tuesday");
Day day = eoDays.objectAtIndex(index);

That's another interesting solution, though I think the previous one is more adapted to my needs

with regards,
--

Lachlan Deck


Thanks a lot for your help !

Fabrice

www.icconsulting.mc

International Corporate Consulting
Palais de la Scala
1 avenue Henri Dunant
Suite 1155
MC - 98000 Monaco

Skype: fabrice.pipart
Tel.  +377 97 98 21 04 (direct)
Fax. +377 97 70 88 07




 _______________________________________________
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: Child EditingContext and fetches
      • From: Lachlan Deck <email@hidden>
References: 
 >Child EditingContext and fetches (From: Fabrice Pipart <email@hidden>)
 >Re: Child EditingContext and fetches (From: Lachlan Deck <email@hidden>)

  • Prev by Date: Re: Webobjects-dev Digest, Vol 3, Issue 187
  • Next by Date: Re: Basic Question (Webobjects-dev Digest, Vol 3, Issue 187)
  • Previous by thread: Re: Child EditingContext and fetches
  • Next by thread: Re: Child EditingContext and fetches
  • Index(es):
    • Date
    • Thread