Closed andyrichardson closed 8 years ago
So, if I'm understanding this correctly, this is in the context of composed models, right?
When you set up your composition, set the many flag to true, like this:
Person.compose(Person, 'friends', 'has_friend', {many: true})
Then the composition will behave this way; it will always be an array.
Please reopen and let me know if I've misinterpreted the problem here! :)
Thanks @jonpacker - solved my problem!
Retreiving nodes When retrieving nodes from the database, regardless of the number of nodes returned, the result is always in an array.
No results
results = [ ]
One result
results = [ {id: 10, name: 'Joe'} ]
Many results
results = [ {id: 10, name: 'Joe'}, {id: 11, name: 'Jess'} ]
Retrieving nodes with relationships
Unfortunately, when working with relationships it's not as simple. Consider the following examples.
No friend relations
One friend relation
Many friend relations
In the above, there is inconsistency in the type of relationship data being returned. A relationship can either be undefined, an object, or an array of objects. Semantically this doesn't make sense, especially in the second case where a related node is defined as the relationship itself rather than a member of a collection of relationships.
Added to this, extra conditional statements are required to determine the type of data being returned.
Let me know if I'm missing something and keep up the good work!