mercredi 21 janvier 2015

Association works in Store, but fails to persist

I created an App with ember-cli, sailsJS and mongoDB to get used to working with emberJS. However, I'm not able to create a hasMany Relationship.


When I add an article for a friend, the save Method functions as expected and the article will be displayed on the page. But when i refresh the page or open another Route and go back the article is gone. So I checked the JSON Output:



... http://host/api/friends
{
"friends": [
{
"firstName": "John",
"lastName": "Doe",
"email": "john@doe.com",
"twitter": "@jd",
"totalArticles": 0,
"createdAt": "2015-01-21T15:44:47.962Z",
"updatedAt": "2015-01-21T15:44:47.962Z",
"id": "54bfc96f6daa8f4836219884"
}
]}
... http://host/api/articles
{
"articles": [
{
"createdAt": "2015-01-21T17:58:37.849Z",
"description": "axe",
"notes": "woah",
"state": "borrowed",
"friend": "54bfc96f6daa8f4836219884",
"updatedAt": "2015-01-21T17:58:37.849Z",
"id": "54bfe8cdcf5c02f6382a6620"
}
]}


Looking at the JSON Output, an article has a relation with the friends id, but the friend is missing a relation to his articles, although I defined a hasMany Relation in the models.


This is the save-Method, which apparently works to save the data correctly into the store but not into the DB:



actions: {
save: function() {
var _this = this;
var model = this.modelFor('articles/new');

model.save().then(function(){
_this.transitionTo('articles');
});
},
...


Are there suggestions on how to fix the problem? The full project is hosted on github: http://ift.tt/1utCqOE





Aucun commentaire:

Enregistrer un commentaire