Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc suggestion for Relationships > Saving section #161

Open
dale42 opened this issue Nov 13, 2016 · 1 comment
Open

Doc suggestion for Relationships > Saving section #161

dale42 opened this issue Nov 13, 2016 · 1 comment

Comments

@dale42
Copy link

dale42 commented Nov 13, 2016

In the code example used in the Relationships > Saving section:

actions:{
    addComment(comment, author){
      //Create the comment
      const comment = this.store.createRecord('comment',{
        comment: comment,
        author: author
      });
      //Get our post
      const post = this.controller.get('model');
      //Add our comment to our existing post
      post.get('comments').pushObject(comment);
      //Save the child then the parent
      comment.save().then(() => post.save());
    }
  }

"comment" is used both as a function parameter and a constant name. I found this example initially confusing because I was reading quickly the first time through, and I'm a relatively new Ember user.

I was also experiencing the problem in #160 and though I might be missing the belongsTo relationship. I thought perhaps the example might be wrong. An explicit note that the belongsTo relationship isn't required would have been reassuring. :)

Suggestions:

  • Change the function parameter to: addComment(commentText, author) or something similar
  • Explicitly note in comments that the belongsTo definition is not required

For example:

actions:{
    addComment(commentText, author){
      //Create the comment
      const comment = this.store.createRecord('comment',{
        // Do not need to specify the belongsTo attribute  
        // of post: post, it's added automatically
        comment: commentText,
        author: author
      });
      //Get our post
      const post = this.controller.get('model');
      //Add our comment to our existing post
      post.get('comments').pushObject(comment);
      //Save the child then the parent
      comment.save().then(() => post.save());
    }
  }
@dweremeichik
Copy link
Contributor

@dale42 sorry about the headache, would you consider submitting a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants