My goal is to persist a simple relationship between two breeze entities on my OData server.
I've setup a server, I am able to:
- insert data
- query data
- create a relation between two entities client-side
- BUT not able to persist the relationship server-side.
Any ideas of what I'm missing?
Below is my setup details
- I'm using OData/MongoDB backend running JayData on Node.js (virtualBox, ubuntu 12.04, node.js, MongoDB)
- I have created a simple data model with a user and a person entity based on this stack overflow question. This is the JayData datamodel definition
>
$data.Class.define("$org.Types.user", $data.Entity, null, {
Id: {type: "id", key: true, computed: true, nullable: false },
Person: { type: "$org.Types.person", inverseProperty: "User", required:true },
EmailAddress: { type: "string"},
Password: { type: "string"}
}, null)
$data.Class.define("$org.Types.person", $data.Entity, null, {
Id: {type: "id", key: true, computed: true, nullable: false },
User: { type: "$org.Types.user", inverseProperty: "Person"},
FirstName: { type: "string"},
LastName: { type: "string"}
}, null);
$data.Class.defineEx("$org.Types.Context", [$data.EntityContext, $data.ServiceBase], null, {
User: {type: $data.EntitySet, elementType: $org.Types.user } ,
Person: {type: $data.EntitySet, elementType: $org.Types.person }
});
exports = $org.Types.Context;
- I'm able to query the data using Breeze.js
- I'm able to insert User and Person entities using Breeze.js
- I'm able to set a relation in Breeze and I see the changes to the entities
- I've updated Breeze.js to 1.3.3
>
var manager = new breeze.EntityManager('api/');
// other breeze initialization stuff, metadata etc.
var person = manager.createEntity('Person', undefined, breeze.EntityState.Detached);
var user = manager.createEntity('User', undefined, breeze.EntityState.Detached);
// set other fields, name, email, password
user.Person(user);
manager.addEntity(user);
manager.addEntity(person);
// save the changes
manager.saveChanges().then(function() { // etc
But I only see two OData post for the two entities but nothing to tie the two entities together
- I ruled out the OData adapter as both the WebAPI and OData adapter call the same functions in the Breeze code base and there are multiple Breeze/WebAPI that demonstrate the ability to query and inserted related entities.
- I haven't seen a Breeze.js / OData sample that seems to address this.
- The closest example that works is a datajs code sample. It posts the related entity to /$links/ to create the relationship (something I don't see in the OData adapter of neither Breeze.js or JayData).