Re: Fetching entities where the relations are known (rakel)

  • The reason the predicate didn't work, was that my currentPerson
    object was NOT the NSManagedObject instance I thought it was, it was
    a proxy (an instance of the class _NSControllerObjectProxy as it
    turned out) which I received from the selection in an
    NSArrayController. (According to the documentation it shall be
    possible to use the predicate I described, but this of course
    requires the correct objects :-)

    Now, the question is as follows, given an NSPopUpButton, bound to an
    NSArrayController which in turn is bound to a ManagedObjectContext,
    how do I get an NSManagedObject instance corresponding to the
    selected item in the popup?


    > Från: rakel <rakel...>
    > Datum: tisdag 10 okt 2006 23.13.06 GMT+02:00
    > Till: <cocoa-dev...>
    > Ämne: Fetching entities where the relations are known
    > I have a Core Data model, which looks something like [Person] ----*
    > [Value] *---- [Variable] I.e. the Person entity has a to-many
    > relation to the Value entity, and the Variable entity also has a to-
    > many relation to Value. Value in turn has a to-one relation with
    > both Person and Variable (and before anyone asks, no, this is not a
    > "many to many"-relational table as seen in ordinary relational
    > databases).
    > Also, the Value entity has a date attribute, called assessmentDate.
    > Now, in my application I have a Person instance and a Variable
    > instance. How do I get all the corresponding Value instances,
    > sorted on assessmentDate?
    > I have been trying around with fetch predicates, with no success
    > ( [NSPredicate predicateWithFormat:@"personr == %@",
    > currentPerson ] does not do the trick). Another idea could be to
    > ask the Person for the set of all its Values and then the Variable
    > for the set of all its Values, and then to take the union of those
    > two sets -- but this won't sort the Values.
    > Regards /Dan
previous month october 2006 next month
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today