• 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: Is it possible to override a property in an Entity subclass in CoreData?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible to override a property in an Entity subclass in CoreData?


  • Subject: Re: Is it possible to override a property in an Entity subclass in CoreData?
  • From: "Barry Wark" <email@hidden>
  • Date: Wed, 20 Feb 2008 12:33:15 -0800

Ben,

Thank you for your reply!

On Feb 19, 2008 9:45 PM, Ben Trumbull <email@hidden> wrote:
> >I would like to emulate property type overloading in CoreData. The
> >model might look something like:
> >
> >FooEntity (Abstract) {prop1:string, prop2 : UNKNOWN}
> >BarEntity (inherits FooEntity) {prop2 : int}
> >BazEntity (inherits FooEntity) {prop2 : double}
>
> Core Data doesn't support this.
>
> If you eliminate the property on FooEntity, you could do separate
> queries using -setIncludesSubentities: to fetch exactly BarEntity and
> BazEntity types and union the results.  Your managed object classes
> could all support accessors for 'prop2' (e.g. a protocol, etc) so
> dropping the property from the abstract entity wouldn't be apparent
> to the code.

This is a promissing lead, but we're hoping to let the user design a
query using NSPredicateEditor. My (limited) understanding is that it
will be hard to create multiple queries from custom
NSPredicateEditorRowTemplates--NSPredicateEditor appears designed to
create a single NSPredicate. It's (of course) quite possible I haven't
grokked NSPredicateEditor fully yet.

>
> If you didn't need to search on the property, you could use the
> transformable attribute type, and have something completely different
> in each row, let alone subentity.

Being able to perform fetches with predicates on the property is a
requirement, unfortunately.

>
> >The CoreData fetch could then translate the
> >original predicate ("prop1=='test' && prop2 == 10") into a query into
> >the appropriate column comparisons
>
> How would we know which prop2 the prop2 in the predicate refers to ?
>
> The columns have different types, and we consider strong typing a feature.
>
> Then there's the problem that integers and doubles do not compare or
> cast with perfect fidelity.
>
>      long long x = (long long)0xDEADBEEFDEADBEEFll;
>      double y = (double)x;
>      long long z = (long long)y;
>
> And z != x.  Ouch.  Now what ?
>
> How does your code know what it's going to get back and how to use it
> without loss of precision ?

Double ouch. Obviously you all have thought much more about this than
I have. I agree that strong typing is a good thing and wouldn't want
to give that up.

>
> Why do you want to conflate a column with different types anyway ?

I'm trying to emulate a key-value map. The application is a custom job
for acquiring scientific data. Each trial may have a different, and
arbitrary set of parameters (the set of parameters can be described by
a key-value map) and the value of the parameters vary in type, though
the key can (fortunately) always be a string. So in my example, prop1
corresponds to the key and prop2 to the parameter value. The
researchers need to be able to perform a query on the parameters so
that they can, e.g. find all trials with a particular set of parameter
key-value pairs. We've implemented the solution as I described in the
OP, but I'm wondering if there's a prettier way to accomplish this
goal.

barry

P.S. Thanks for the great work on CoreData!
_______________________________________________

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

  • Prev by Date: Re: Mutable Convenience Methods
  • Next by Date: Re: Singleton as a common area?
  • Previous by thread: Is it possible to override a property in an Entity subclass in CoreData?
  • Next by thread: [Meet] : Los Angeles CocoaHeads Thursday 2/21 at 7:30pm
  • Index(es):
    • Date
    • Thread