visoft/ruby_odata — pull request #56 by Takemikazuchi (2014-08-03 05:48:28+00:00)
Title: patch added collections to work with deep inserts

Hi,

I have a patch here that fixes an issue when you attempt to do a deeply nested insert. At least in Odata 4 it is possible to send an object with a collection of related objects. From what I can tell in the comments in class_builder.rb ruby_odata attempts to support this as well. However an Odata server expects just the name of the entity followed by array of entities to be created, linked to the parent entity, whereas ruby_odata attempts to submit the collection within a `_results` key.

http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793073

I am reasonably confident this is also part of Odata 3 but cannot find a definite, unambiguous source. See the Section 10.3.2 of the Odata3 spec:

>10.3.2.2. Create Related Entities When Creating an Entity

>A service that supports creating entities SHOULD support creating related entities as part of the same request.

>A request to create an entity MAY specify related entities that should also be created. The related entities MUST be represented using the appropriate inline representation of the navigation property.

>On success, the service MUST create each entity and relate them.

>On failure, the service MUST NOT create any of the entities.

http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol/
As you can tell, unlike the Odata4 spec it isn't very clear exactly how you are supposed to post related entities.

I understand some additional tests may be needed before this pull request is accepted. I just wanted to make sure my reasoning is sound and the maintainers are interested before I moved forward with this patch.