Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:20:14+00:00 2026-06-18T09:20:14+00:00

Can I use Collection.get(id) to find a model within a Backbone.js collection by cid,

  • 0

Can I use Collection.get(id) to find a model within a Backbone.js collection by cid, for a model not yet saved to the server?

From the documentation, it seems like .get should find a model by either its id or cid. However, collection.get(cid) doesn’t find the model, whereas this does, collection.find(function(model) {return model.cid===cid; }). Presumably I’m overlooking something basic.

jsFiddle for example below

var Element = Backbone.Model.extend({});
var Elements = Backbone.Collection.extend({ model:  Element });

var elements = new Elements(), el, cids = [];

for (var i=0; i<4; i++) {
    el = new Element({name: "element"+i})
    elements.add(el);
    cids.push(el.cid);
}

console.log(cids);
el1 = elements.get(cids[0]);     
console.log(el1);  // undefined


el1a = elements.find(function(model) { return model.cid === cids[0]; });
console.log(el1a);  // success

Backbone.js – id vs idAttribute vs cid

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:20:15+00:00Added an answer on June 18, 2026 at 9:20 am

    In backbone 0.9.9 (see changelog), they removed the .getByCid() method and folded that functionality directly into .get() — if you’re using below 0.9.9, you can use the .getByCid() method; I think they’ve since removed it from the docs to reflect the most current state of the library.

    Edit:

    See @Ferdinand Prantl’s comment below for more detail, but passing the cid as the property of an object literal will accomplish what you’re looking for here: .get({ cid: "xxx" }). My apologies for any confusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to find an easy to use, .net native way to get
If I have a collection of div elements, I can use CSS to have
I have a collection that use as a cache. How can I limit the
In C# I use a Queue collection. I can easily Enqueue or Dequeue. Okay,
I have a SMTP account that does not use encrypted connection. I can use
I can use the following to get the contents of a folder with no
Believe it or not I can not find an answer anywhere, it must be
Can I use scala List in Java, like : import scala.collection.immutable.List; class HelloScalaList {
I'm trying to find a way to use Backbone-relational submodels with RequireJS, where the
How can I prevent Django, for testing purposes, from automatically fetching related tables not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.