Help inserting many-to-many relatioship
Sarwat Khan <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
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.