CoreData NSTreeController Binding Relationship Problem

  • Hello,
    I have two core data entities,  Category and Project.  Category is
    related to Project using the "project_rel" (one to many).  Project is
    related to Category using the "category_rel".  The inverse is set for
    both of them.  So basically I want to list all projects within a
    category.

    I have a tree controller that is setup using the following bindings:

    Object Controller:  Mode=>Entity  Entity Name=> Category
    Key Paths:  Children => project_rel

    Last but not least, I have a button hooked up to the add method on the
    NSTreeController.  I have also tried the addChild method, and written
    my own method to programmatically add the category entity and all
    result in the same error.  When I click the button I get the following
    error:  the entity Category is not key value coding-compliant for the
    key Project

    This has got me stumped and everything I find says that I have this
    setup correctly.

    Thanks in advance
  • There are a couple of problems:

    1) The tree controller manages content of a single entity type - you
    have two different entity types. One way around this is to make both
    entities sub-entities of another entity.
    2) Your relationships don't follow Cocoa naming conventions
    (categoryRel versus category_rel) which has implications in Key-Value
    Coding.
    3) The Children key path must be implemented (even if it just returns
    nil) by every object the tree controller manages. So, if you have a
    Category as the root of the tree, and Projects as its children, the
    Projects must implement the Children key path as well as the Category.

    There's a recently published sample code that might give you some
    additional insight, http://developer.apple.com/samplecode/AbstractTree/

    Wil

    On Jan 15, 2008, at 9:03 PM, Chris Schmitt wrote:

    > Hello,
    > I have two core data entities,  Category and Project.  Category is
    > related to Project using the "project_rel" (one to many).  Project
    > is related to Category using the "category_rel".  The inverse is set
    > for both of them.  So basically I want to list all projects within a
    > category.
    >
    > I have a tree controller that is setup using the following bindings:
    >
    > Object Controller:  Mode=>Entity  Entity Name=> Category
    > Key Paths:  Children => project_rel
    >
    > Last but not least, I have a button hooked up to the add method on
    > the NSTreeController.  I have also tried the addChild method, and
    > written my own method to programmatically add the category entity
    > and all result in the same error.  When I click the button I get the
    > following error:  the entity Category is not key value coding-
    > compliant for the key Project
    >
    > This has got me stumped and everything I find says that I have this
    > setup correctly.
    >
    > Thanks in advance
  • Actually, disregard my second comment, with respect to the
    relationship names - that was not correct.

    Wil

    On Jan 15, 2008, at 9:44 PM, William Turner wrote:

    > There are a couple of problems:
    >
    > 1) The tree controller manages content of a single entity type - you
    > have two different entity types. One way around this is to make both
    > entities sub-entities of another entity.
    > 2) Your relationships don't follow Cocoa naming conventions
    > (categoryRel versus category_rel) which has implications in Key-
    > Value Coding.
    > 3) The Children key path must be implemented (even if it just
    > returns nil) by every object the tree controller manages. So, if you
    > have a Category as the root of the tree, and Projects as its
    > children, the Projects must implement the Children key path as well
    > as the Category.
    >
    > There's a recently published sample code that might give you some
    > additional insight, http://developer.apple.com/samplecode/AbstractTree/
    >
    > Wil
    >
    > On Jan 15, 2008, at 9:03 PM, Chris Schmitt wrote:
    >
    >> Hello,
    >> I have two core data entities,  Category and Project.  Category is
    >> related to Project using the "project_rel" (one to many).  Project
    >> is related to Category using the "category_rel".  The inverse is
    >> set for both of them.  So basically I want to list all projects
    >> within a category.
    >>
    >> I have a tree controller that is setup using the following bindings:
    >>
    >> Object Controller:  Mode=>Entity  Entity Name=> Category
    >> Key Paths:  Children => project_rel
    >>
    >> Last but not least, I have a button hooked up to the add method on
    >> the NSTreeController.  I have also tried the addChild method, and
    >> written my own method to programmatically add the category entity
    >> and all result in the same error.  When I click the button I get
    >> the following error:  the entity Category is not key value coding-
    >> compliant for the key Project
    >>
    >> This has got me stumped and everything I find says that I have this
    >> setup correctly.
    >>
    >> Thanks in advance

previous month january 2008 next month
MTWTFSS
  1 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