Re: Help inserting many-to-many relatioship
Chuck Hill <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Organization | Global Village Consulting, Inc. |
| Message-ID | <[email protected]> |
Hi,
Reverse the order of story creation:
ec.insertObject(story); // Always do this FIRST!
story.takeValueForKey(((Session)session()).getUserId(), "userId");
story.takeValueForKey(new NSTimestamp(), "datePosted");
See if that helps.
Chuck
Sarwat Khan wrote:
>
> Hi,
>
> I'm painfully learning EOF (are there any good docs available??) and I'm
> stuck trying to insert a new Story record that is many-to-many related
> to Category records.
>
> I've tried a few things, and the most correct seeming thing I was able
> to come up with was this, which is basically to go through each category
> that a story will be related to and
> addObjectToBothSidesOfRelationshipWithKey.
>
> >>>>
> story.takeValueForKey(((Session)session()).getUserId(), "userId");
> story.takeValueForKey(new NSTimestamp(), "datePosted");
> ec.insertObject(story);
>
> //for each category, add the story to both sides of the relationship
> Enumeration ite = selectedCategories.objectEnumerator();
> while (ite.hasMoreElements())
> {
> EOGenericRecord cat = (EOGenericRecord)ite.nextElement();
> cat.addObjectToBothSidesOfRelationshipWithKey(story, "stories");
> }
>
> ec.saveChanges();
>
> //refault the object so all relationships are loaded next fetch
> ec.invalidateObjectsWithGlobalIDs(new
> NSArray(ec.globalIDForObject(story)));
> <<<<
>
> However, I get a baffling exception,
>
> EvaluateExpression failed: <snip>: "INSERT INTO story(user_id,
> date_posted, url, story_id, department, category_id, title, content,
> comment_id) VALUES (?, ?, NULL, NULL, ?, NULL, ?, ?, NULL)"
> withBindings: 1:1(userId), 2:2002-10-29 16:29:53(datePosted), <snip>
>
> Why is EOF trying to insert a story record with NULL values? It has the
> correct bindings (as withBindings: shows). If I take out that loop in
> that code snippet, it is able to insert properly. Is there something I
> have to do properly in my EOModel?
>
> Thanks for any info,
>
> Sarwat.
>
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof
--
Chuck Hill [email protected]
Global Village Consulting Inc. http://www.global-village.net