Skip navigation.
 
mlre: Core Data dynamic attributes and fetching
FROM : Ben Trumbull
DATE : Sat May 24 22:47:42 2008

At 2:56 AM -0700 5/24/08, <email_removed> 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

Related mailsAuthorDate
mlCore Data dynamic attributes and fetching Ben May 24, 09:36
mlre: Core Data dynamic attributes and fetching Ben Trumbull May 24, 22:47
mlRe: Core Data dynamic attributes and fetching Ben May 25, 08:33