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 8934087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:42:10+00:00 2026-06-15T09:42:10+00:00

I’m using MongoDb/Lithium php framework with backbone. I want all my model id(s) and

  • 0

I’m using MongoDb/Lithium php framework with backbone.

I want all my model id(s) and idAttribute(s) to be same as my database document id (i.e ‘_id’/mongoid)

Questions:

  1. When I print the value of model.idAttribute, it is shown as just _id.
  2. When I print model.get(‘idAttriubte’), it is undefined.
  3. How do I ensure that the idAttribute is set as the same as the database id/mongoid?

Here is the model class:

window.app.IHoliday = Backbone.Model.extend({
    urlRoot: HOLIDAY_URL,
    idAttribute: '_id',
    id: '_id',
    // Default attributes for the holiday.
    defaults: {
    },

    initialize: function(props) {
    },      
});

Here is the view code, calling fetch on the model. The mongoid for the document is passed to this page as a hidden input (holiday_id).

console.log('Holiday URL:' + HOLIDAY_URL );
        var Holiday = new window.app.IHoliday({ _id: holiday_id });
        console.log('HOLIDAY before fetch: \n' + JSON.stringify(Holiday));
        Holiday.fetch(
                {
                    success: function(){
                        //alert('Holiday fetched:' + JSON.stringify(Holiday));
                        console.log('HOLIDAY Fetched: \n' + JSON.stringify(Holiday));
                        console.log('Holiday name:' + Holiday.get('holiday_name'));
                        console.log('Holiday id:' + Holiday.id);
                        console.log('Holiday idAttribute:' + Holiday.idAttribute);
                        console.log('Holiday idAttribute:' + Holiday.get('idAttribute'));
                    }
                });

The output from firebug console:

HOLIDAY before fetch:{"_id":"50bcaab24fbe3dfc1700000b"}
GET http://localhost:8080/li3/holidays/load/50bcaab24fbe3dfc1700000b 200 OK

HOLIDAY Fetched: 
{"_id":"50bcaab24fbe3dfc1700000b","holiday_name":"eeeeeeeeeeeeeeeee","description":"","star_rating":"3","holiday_type":"family","rooms":"1","adults":"2","child":"0","emails":""}

Holiday name:eeeeeeeeeeeeeeeee
Holiday id:50bcaab24fbe3dfc1700000b
Holiday idAttribute:_id
Holiday idAttribute:undefined

EDIT:
The following worked…after commenting out the entry for id in the model class:

    window.app.IHoliday = Backbone.Model.extend({
    urlRoot: HOLIDAY_URL,
    //id: '_id',
    idAttribute: '_id',
    // Default attributes for the holiday.
    defaults: {
    },

    initialize: function(props) {
    },
  • 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-15T09:42:11+00:00Added an answer on June 15, 2026 at 9:42 am

    idAttribute contains the name of the member of the class wich will be use as the id. So, if you use idAttribute: '_id', Backbone will use the member _id as the id of your class.

    If you want to use the attribute holiday_id as the id of your class IHoliday, you may try :

    window.app.IHoliday = Backbone.Model.extend({
        urlRoot: HOLIDAY_URL,
        idAttribute: 'holiday_id',
        // Default attributes for the holiday.
        defaults: {
        },
    
        initialize: function(props) {
        },      
    });
    
    var Holiday = new window.app.IHoliday({holiday_id : holiday_id });
    

    Backbone will use the holiday_id attribute instead of the regular id attribute.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.