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

  • Home
  • SEARCH
  • 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 7900123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:53:21+00:00 2026-06-03T08:53:21+00:00

I was having issues idAttribute causing .save() to report a bad isNew() value when

  • 0

I was having issues idAttribute causing .save() to report a bad isNew() value when I wanted to add a new model to the server with the ID pre-populated.. which led me to keep it off and set the model.id manually.

Here’s my View:

    RecordListItemView = Backbone.View.extend({
        initialize:function () {
            var record = this.model.attributes;
            if (record.user_id) {
                this.model.id = parseInt( record.user_id );
                record.id = parseInt( record.user_id );
                    // Added this so ID would show up in model and .attributes
            }
            this.model.bind("change", this.render, this);
            this.model.bind("destroy", this.close, this);
        },

        render:function (eventName) {
            $(this.el).html(this.template(this.model));
            console.log(this);
            return this;
        }
    });

At this point I am unable to retrieve any records using collection.get(id), though I am able to do so via collection.getByCid(cid) just fine.

Here’s my console.log output:

    d
      $el: e.fn.e.init[1]
      cid: "view36"
      el: HTMLLIElement
      model: d
        _callbacks: Object
        _escapedAttributes: Object
        _pending: Object
        _previousAttributes: Object
        _silent: Object
        attributes: Object
        id: 15
        user_id: "15"
        user_name: "Test"
        __proto__: Object
      changed: Object
      cid: "c8"
      collection: d
      id: 15
      __proto__: x
    options: Object
    __proto__: x

Is there a way to fix collection.get(id) without having to alter my database to include an id field? (Currently using user_id as the pk)

As posted below by Benjamin Cox: (with parseInt() removed as unnecessary)

Replace

    this.model.id = record.user_id;

with

    this.model.set({ id: record.user_id });

.. to avoid bypassing the Model’s change event which in turn updates the Collection’s internal_byId[] array.

After testing both, I wound up using mu is too short’s parse suggestion..

    parse: function(response) {
        return {
            id: response.user_id,
            user_id: response.user_id,
            user_name: response.user_name
        };
    }
  • 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-03T08:53:23+00:00Added an answer on June 3, 2026 at 8:53 am

    The reason that calling collection.get(id) doesn’t find your model is that you’re bypassing Backbone’s event mechanism when you do:

    this.model.id = parseInt( record.user_id );
    

    If you do this instead:

    this.model.set({ id: parseInt(record.user_id)});
    

    then the Backbone event code in the model’s set() method will fire a “change:id” event. The collection, in turn, listens for this event and updates it’s internal _byId[] array variable. Later, when you call collection.get(id), this array is used to search for the matching model.

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

Sidebar

Related Questions

Having issues calling the ReportingService2005.FindItems() method from within powershell v2. $rs = New-WebServiceProxy -Uri
Im having issues trying to get a custom snapin to display in the Add/Remove
I am new to android development and I have been having issues with Force
having issues getting a value from a NSString in my view controller to my
At work we're having issues with different people wanting/suggesting different names for a new
Im having issues making the code below to work. Basically, I wanted to move
I'm having issues deleting client cookies with the cfcookie tag, I'm setting the value
Im having issues with accessing the value of a variable in NodeJS. Here is
I'm having issues uploading a pdf to my server. The upload_max_filesize is 2M and
Having issues attaching a Database and full text catalog from server A to server

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.