• 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: nil properties in Fetch Requests
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nil properties in Fetch Requests


  • Subject: Re: nil properties in Fetch Requests
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 12 Jul 2005 08:13:04 -0700


On Jul 11, 2005, at 6:33 AM, Óscar Morales Vivó wrote:

I have a fetch request like the following:
isMale == 1 AND dateOfBirth < $CALLERBIRTHDAY AND dateOfDeath >= $CALLERBIRTHDAY
Where isMale is a non-optional boolean property, and both dateOfBirth and dateOfDeath are optional date properties.
I know I cannot instantiate $CALLERBIRTHDAY with nil. In those cases where I find it, I can substitute it for [NSDate distantPast] and [NSDate distantFuture] as appropriate.
However I don't know how and if the predicate will work if dateOfBirth and/or dateOfDeath haven't been set for any of the entities that go through it. Depending on the behavior I'll have to pretty much forget about using fetch requests for my needs and go through code, which kind of defeats the purpose of the fetch requests in the first place.


If dateOfBirth or dateOfDeath is not set (that is, if it is nil in an instance), and $CALLERBIRTHDAY is non-nil, then the predicate does not match.

If you want to include matches where the dateOf values may be nil, could you not use a predicate that allows for that?

isMale == 1 AND (dateOfBirth < $CALLERBIRTHDAY || dateOfBirth = nil) AND (dateOfDeath >= $CALLERBIRTHDAY || dateOfDeath = nil)



I've also noticed I could sidestep the problem completely if I set the default value for the "dateOfBirth" property to [NSDate distantPast] and the one for "dateOfDeath" as [NSDate distantFuture]. The Xcode 2.1 model editor won't allow me to do so (worth filing a bug?)

It'll be a duplicate, but may be worth filing  :-)

but I could set them by code as I've read in the documentation.
The only problem is that I don't know at what point I should set them before the object model starts being used, nor from which object (custom document class?). I know this has been discussed elsewhere but I'm having problems finding it so pointers to it will be greatly appreciated.


I presume you're using an NSDocument-based application?

- (id)managedObjectModel
{
    // declare instance variable, NSManagedObjectModel *myMom
    if (myMom != nil)
    {
        return myMom;
    }

myMom = [super managedObjectModel];
NSEntityDescription *entity = [[myMom entitiesByName] objectForKey:@"Entity"];
NSAttributeDescription *dateAttribute = [[entity attributesByName]
objectForKey:@"date"];
[dateAttribute setDefaultValue:[NSDate date]];
return myMom;
}



mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: nil properties in Fetch Requests
      • From: Óscar Morales Vivó <email@hidden>
References: 
 >[FOLLOWUP] nil properties in Fetch Requests, part 2 (From: Óscar Morales Vivó <email@hidden>)
 >nil properties in Fetch Requests (From: Óscar Morales Vivó <email@hidden>)

  • Prev by Date: Drawing an NSImage into a GWorld
  • Next by Date: Re: nil properties in Fetch Requests
  • Previous by thread: Re: nil properties in Fetch Requests
  • Next by thread: Re: nil properties in Fetch Requests
  • Index(es):
    • Date
    • Thread