I have a system where I am constructing C+J for a collection of items, and those items refer to other collections (and in particular to subsets thereof).
Consider a hypothetical system with people, houses and cars. Each person has one house, but can have more than car, but more than one person can live in a house, and a car can be shared between multiple people. A pretty standard set of one-to-many and many-to-many relationships
I am currently modelling this along these lines:
"items" : [
{ "href" : "/people/1"
.... "data" : [ { name : name, value : "john"} ],
"links" : [ { rel : "cars", href="/cars?where=reg=123ABC1 or reg=456EFG1" }, { rel : "house", href="/houses/1" }
}]
In essence, the relations are links which return the related items. All good so far (although if I am misunderstanding how I should expose such relationships, please let me know)
My question is what to do when I reassemble an object model on the client end. In the spirit of not having prior structural information (i.e. that a person has one house but 1 or more cars), I am wondering how to derive from the above that the property house should be one-to-many, but cars should be many to many. In particular, when the number of cars is 1 not 2. In essence, the difference between a and [a].
The primary issue is that /houses/1 returns a collection with a single item in it, and this can't be differentiated from the filtered collection of cars, which also returns a collection with a single item if there is only 1 car. Without doing something horrible (like noting that all properties that end with an s should be converted to lists, whereas those without should be single properties), is there a way to achieve what I want with the basic C+J standard? If not, is there already a suitable extension?, and if not, suggestions as to a suitable approach would be gratefully accepted.
There is a similar issue with the template, if I want to specify the car/house from the person, but I suspect the direction to go for that will fall out of the same answers.