strongloop / loopback-example-offline-sync

Offline sync, change tracking, and replication.
http://loopback.io/doc/en/lb2/Synchronization.html
Other
285 stars 110 forks source link

Failed to create Embedded Model in the client side #78

Closed nutboltu closed 8 years ago

nutboltu commented 8 years ago

I created a Model named Project where ProjectMembers are embedded model. Here are my model: Project.json { "name": "Project", "base": "PersistedModel", "strict": "throw", "persistUndefinedAsNull": true, "trackChanges": true, "properties": { ... }, "relations": { "members": { "type": "embedsMany", "model": "ProjectMember", "property": "members", "options": { "validate": true, "forceId": false } } } } ProjectMember.json { "name": "ProjectMember", "base": "Model", "idInjection": true, "properties": { ... }, "validations": [], "relations": {}, "acls": [], "methods": [] } In the server side model-config.json I updated the datasource as below: "Project": { "dataSource": "my_db" }, "ProjectMember": { "dataSource": "transient" } And in the client side in lbclient/models/ I added 2 files local-project.json and remote-project.json as exactly same as local-todo.json and remote-todo.json. I updated the client side model-config.json file as below: "RemoteProject": { "dataSource": "remote" }, "LocalProject": { "dataSource": "local" }

In the client controller I run the following codes: ProjectModel.create($scope.project) .then(function(project) { var owner = loginDetails.getLoginUser();// the member owner.role = 'owner'; owner.status = 'active'; project.members.create(owner); //shows error: couldn't read property $scope.project = {}; $scope.$apply(); }); It creates the Project but failed to create the embedded model. It displays "Couldn't read property create undefined"? Is there any way to create embedded model in the client side?

superkhau commented 8 years ago

Please post questions at https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Questions for more details.

Is there any way to create embedded model in the client side?

@bajtos ^