Re: Inserting/Deleting Records From Within EOGenericRecord
Re: Inserting/Deleting Records From Within EOGenericRecord
- Subject: Re: Inserting/Deleting Records From Within EOGenericRecord
- From: email@hidden
- Date: Wed, 10 Mar 2004 12:54:24 -0500
- Priority: normal
Thanks for the response everyone. I believe this might help the rest of the mailing list.
----- Original Message -----
From: David Griffith <email@hidden>
> If you are using custom java classes, you can instantiate an
> instance of
> subscription like this:
>
> Subscription myNewSubscription = new Subscription();
Wow! I had no idea! this is so much more elegant :) thanks :)
> > subscription.setSubscriberId(this.subscriberId());
>
> This looks like you are using the setter method to set a value
> that you are
> getting from the getter method for the same value.
>
> You you myNewSubscriber.subscriberId();
> To get the value associated with subscriberId from that object.
>
> You use myNewSubscriber.setSubscriberId(someID) to set the value.
>
> If you are trying to set it to the primary key of the Subscriber,
> there is
> another way to do it. Ask if that's what you want to do.
Actually this in this.subscriberId() is actually Subscriber.java (the EOGenericRecord). Subscription is another EOGenericRecord (or custom class. Here is the relationship:
Subscription.java <<-> Subscriber.java
So when I try to create a new subscription from within Subscriber.java I do:
//(thanks to you)
Subscription subsription = new Subscription();
//I insert into the editing context
this.editingContext().insertObject(subscription);
//then I set the foreign key for subscription
subscription.setSubscriberId(this.subscriberId());
// then I save the relationships between subscriber and subscription
this.addObjectToBothSidesOfRelationshipWithKey(subscription,"toSubscriptions");
//then I save
this.editingContext().saveChanges();
But I am getting an Attempt to insert nil error here :
NSInvalidArgumentException: Exception while evaluating takeValue:forKeyPath:'child1.grade', on target:: *** -[NSConcreteMutableArray addObject:]: attempt to insert nil
> >
> > NSInvalidArgumentException: Exception while evaluating
> > takeValue:forKeyPath:'child1.grade', on target:: *** -
> [NSConcreteMutableArray> addObject:]: attempt to insert nil
> >
> Probably you haven't set the relationship to whatever table it is
> relatedto.
I believe I tried that above.
>
> So if you inserted a new subscription called mySubscription, and
> you knew
> the subscriber (you had an object of subscriber) you could say:
>
> mySubscription to
> addToBothSIdesOfRelationshipWithKey(subscriber,"subscriber");
>
> Assuming the relationship from subscription to subscriber is called
> 'subscriber' this will set the relationship to be the subscriber
> object you
> passed it. This will set the primary keys and foreign keys to
> match for
> you.
I notice I had to set the foreign keys myself because
> > Where child1 is another to-many relationship Subscriber.
> >
> > What I don't understand is why a subscription record shows up in
> > toSubscription() when I expressly delete it.
>
> Cause it didn't get removed from the editing context I guess.
Thanks I was able to remove it after using the ec.deleteObject(subscription) method.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.