Question about "To Many" relationships hooks in ERRest
Question about "To Many" relationships hooks in ERRest
- Subject: Question about "To Many" relationships hooks in ERRest
- From: Pascal Robert <email@hidden>
- Date: Mon, 18 Jun 2012 10:52:44 -0400
I'm working on my WOWODC slides, and I'm doing something that I didn't do for many months: updating a 1:N (in fact, it's a N:N with a flatten relationship). So I have a blog entry which can have multiple categories, and I was doing an update to a blog post to add some categories, with:
PUT /cgi-bin/WebObjects/WOWODCBlog.woa/ra/blogEntries/2.json HTTP/1.1
{ "id":2,"type":"BlogEntry", categories: [ {id : 1}, {id : 2} ] }
Problem is: the categories were not linked to the blog post. Worse, if I make the link between a category and the blog entry with a "manual" EOF call, and after I try the same PUT call, it was emptying the relationship! So after debugging, I found that the problem was here:
ERXRestRequestNode.java.updateObjectWithFilter
I was getting into:
if (toManyNode.children().count() == 0 && ERXRestUtils.isPrimitive(toManyNode.value())) {
if (lockedRelationship) {
childObj = null;
} else {
childObj = toManyNode.value();
}
}
toManyNode.id was ok (returns the id I'm passing in), but value() is empty, so I was not reaching the logic below in the method that is adding the objects into the relationship. I fixed it by removed the call to 'toManyNode.value()' and adding :
childObj = IERXRestDelegate.Factory.delegateForClassDescription(destinationClassDescription).objectOfEntityWithID(destinationClassDescription, id, context);
Since then, works perfectly. But since that code was added last year (in commit 35a78ceea4f1c1cb713884d3f02b3f8d048b452c), I'm wondering is my fix is ok or it's me who do something wrong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden