0

I have the following collection:

AisisWriter.Collections.Posts = Backbone.Collection.extend({
  model: AisisWriter.Models.Post,
  // Build the url based on blog id.
  url: function() {
    url = '/api/v1/blogs/' + AisisWriter.blog_id + '/posts/'
    return url;
  }
});

this allows me to do:

var options = { reset: true };
this.writer_posts.fetch(options).then(this.postsRecieved, this.serverError);

this will return me all posts, current six.

I have tired to do:

var options = { reset: true };
this.writer_posts.fetch({id: id}).then(this.postsRecieved, this.serverError);
// id is the id passed into the route, in this case it's #=> {id: 6}

But this still returns me all six posts, I have seen this answer, but I don't think I should have to go through, or extend the model in the middle of code just to append an ID, that and I use the model for the Post, Put and Delete actions while I use the collection for fetching data.

So how do I return one post?

Community
  • 1
  • 1
user3379926
  • 3,855
  • 6
  • 24
  • 42

1 Answers1

0

In general, to get some Model from Collection, you should fetch Collection and then get needed model by id, for example:

this.writer_posts.fetch();

And after Collection will be fetched you get method

this.writer_posts.get(id);

Or you can try to fetch a specific Model by passing required id in the fetch method:

this.writer_posts.fetch({
    data: {
        id: id
    }
});

Or something like that.

Jake Blues
  • 1,033
  • 1
  • 9
  • 12