re: Core Data dynamic attributes and fetching
re: Core Data dynamic attributes and fetching
- Subject: re: Core Data dynamic attributes and fetching
- From: Ben Trumbull <email@hidden>
- Date: Sat, 24 May 2008 13:47:42 -0700
At 2:56 AM -0700 5/24/08, email@hidden wrote:
I have a core data object graph using an SQLite store where several
entities have an attribute containing a date (eg, birthDate). This is
stored as a date type.
I am currently implementing an NSPredicateEditor for building smart
groups. Each smart group simply saves this predicate to an attribute
and then fetches using that.
The problem is that I want to offer to filter by ('days since birth'
== 7), as well as (birthDate == 01/01/01). This is where I have hit a
wall. I can't set a dynamic transient property for daysSinceBirth as
these can't be used in fetch requests, and I can't convert the number
of days to an absolute date as this loses the dynamic-calculation part
of the number.
This is the part I'm not following. Why don't you transform:
'days since birth' == 7 into 'birthDate == $x' where $x =
'currentDate - 7 days'
Generally speaking, you always want to work with absolute time
(seconds since reference date, UTC) in the database. The only place
you should use calendar, human legible dates, or time zones is with
entities like users' Preferences or user's active Session. Obviously
your UI layer needs to represent dates in a way your customers will
appreciate.
Calendar properties are political and historical issues as well as
geographically relative. Calendars make the Unicode spec look like
riding a big wheel. They are generally not useful to store in the
database.
Nothing stops you from using the NSPredicateEditor with 'fake'
properties and then grabbing the predicate it makes and transforming
it into another one. Pulling apart an NSPredicate tree is tedious,
but not hard.
--
-Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden