Re: Can't get a Parent-Child CoreData relationship working
Re: Can't get a Parent-Child CoreData relationship working
- Subject: Re: Can't get a Parent-Child CoreData relationship working
- From: "David House" <email@hidden>
- Date: Mon, 28 Jan 2008 18:51:37 -0500
Wil,
Thanks for the reminder. I have that sample and have looked at it several
times. Looking at it tonight I didn't notice a difference at first, then I
spotted my noob mistake. What I was doing was binding the NSTableView
content property AND the NSTableColumn value property. Of course, this works
sorta because it does display the list of items. But I suppose having both
things bound causes some confusion underneath the hood. By removing the
NSTableView binding, the interface now works perfectly.
So thanks for the help!
David
On Jan 28, 2008 1:47 PM, William Turner <email@hidden> wrote:
> Hi David,
>
> I don't have an answer for you, but it might be helpful to look at the
> Apple sample code
> http://developer.apple.com/samplecode/TwoManyControllers/index.html
> - it deals with a fairly similar problem. Looking at the array
> controller and table view bindings might give you some insights.
>
> Wil
>
> On Jan 28, 2008, at 5:43 AM, David House wrote:
>
> > Sorry to bug the list, but I'm totally stumped on this. I am also
> > very new
> > to Cocoa/CoreData, so this will probably end up being a noob problem.
> >
> > All I'm trying to do is hook up 2 NSTableViews in a Parent-Child
> > relationship. The problem is that when I select items in the Parent
> > TableView, the child view doesn't change to match the parent. What is
> > interesting is that when I first load the view, the child contains
> > all the
> > children, and when I click on any parent, nothing changes. But when
> > I create
> > a new parent, the child table view empties. I followed the CoreData
> > video
> > tutorial on the apple site, but I don't see any difference in my app
> > that
> > would cause this problem.
> >
> > Ok, so here are the details. I have 2 Entities in the Data Model.
> > The parent
> > entity has a relationship to the child. This is a 'To-Many
> > Relationship'.
> > Optional is checked, and Delete Rule is set to Cascade. It has an
> > inverse
> > relationship with the child->parent relationship. The relationship
> > on the
> > child is also marked Optional. The data model looks correct visually
> > with
> > both entities connected as they should.
> >
> > On the user interface side I have 2 NSArrayControllers and 2
> > NSTableViews.
> > On the Parent NSArrayController, the entity is set and Automatically
> > Prepares Content is checked. On the bindings, managedObjectContext
> > is set to
> > the AppDelegate and model key path is managedObjectContext.
> >
> > Now, the child NSArrayController (where I feel the problem must be),
> > the
> > entity is also set and Automatically prepares content is checked.
> > Under
> > bindings, the managedObjectContext is set to exactly the same as the
> > parent.
> > In addition, the contentSet is bound to the parent NSArrayController.
> > Controller key is selection. And model key path is set to the name
> > of the
> > relationship from the parent to the child.
> >
> > On the NSTableViews, the content is bound to the appropriate
> > NSArrayController. I have buttons to control adding/removing items
> > from the
> > list. Adding/removing both parents and children seem to work fine.
> >
> > So far I've tried changing the managedObjectContext and contentSet
> > on the
> > child NSArrayController with no good result. If I change the
> > managedObjectContext, I get an app crash. Changing the contentSet
> > doesn't
> > seem to have much effect.
> >
> > To test this, I just created 2 parent records. Then i selected the
> > first one
> > in the list. I click to add a child record, and give it a name. Now
> > i have 2
> > parent items in the parent table, and 1 child item in the child
> > table. I
> > click the second parent, but the child table view does not change at
> > all (I
> > would expect it to empty because I haven't created a child yet that
> > matches
> > the second parent). Now, if I click on the add button for the
> > parent, I get
> > a new parent record, and the child table DOES clear.
> >
> > After typing this up, now I'm guessing that the child is somehow not
> > getting
> > associated with the parent correctly. But I'm at a total loss where
> > this
> > would be defined. I have reviewed the videos from the apple site
> > over and
> > over. I don't see any steps that I'm missing. The only difference I
> > see is
> > that my app uses a Delegate for binding the managedObjectContext,
> > while the
> > apple demo uses the document owner.
> >
> > I should also mention that I'm running XCode on 10.4.11.
> >
> > Thanks,
> > David House
> > _______________________________________________
> >
> > 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
>
>
_______________________________________________
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