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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:40:20+00:00 2026-06-17T14:40:20+00:00

I would like to use a single Backbone Model that is composed of data

  • 0

I would like to use a single Backbone Model that is composed of data from different URL endpoints. Is it possible to specify multiple URLs within a single model? I’d like to avoid calling AJAX by hand.

Until now, I’ve been using jQuery Deferreds to call multiple URLs and synthesize their results into a single object.

I can think of two options so far: building a Backbone model with a partial model for each URL, or using one URL and then overriding Model.fetch() to call the other URLs. But neither one makes me comfortable.

(Or I can try to bribe the API developer to provide a merged URL endpoint…)

  • 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-17T14:40:21+00:00Added an answer on June 17, 2026 at 2:40 pm

    I think both of the ways you suggested are quite reasonable, but personally I’d vote for the fetch approach.

    Using nested models has the advantage of working “out of the box”; in other words, by using one model for every server <=> client mapping you avoid having to change any Backbone.Model methods. The problem with this approach though is that you wind up with a conglomeration of multiple models.

    If that makes sense anyway (data retrieval aside) then stick to nested models. But if not you’re forcing the rest of your code to work with several models instead of just one solely to keep your data retrieval code simple. If you’d rather just complicate the data retrieval code and keep everything else simple then you’re better off overwriting fetch.

    fetch does one thing, and that is retrieve data via a one-to-one mapping between it and a remote URL. If you want a one-to-many mapping instead it makes perfect sense to just override the default fetch behavior. Plus you know it’s reasonably safe to override fetch because it’s name isn’t _fetch, and Backbone uses the the underscore style to name it’s pseudo-private methods (eg. _validate).

    If you still don’t like either of those approaches, there is one other option: request events. The latest version of Backbone has a new event called request that is triggered whenever a fetch is started. What this means is that you can setup an event handler that retrieves your secondary data in response to the primary data’s request, like so:

    Backbone.Model.extend({
        initialize: function() {
            this.on('request', this.handleRequest);
            _.bindAll(this, 'handleTriggeredResponse');
        },
        handleRequest: function() {
            $.ajax({url: secondDataUrl, complete: this.handleTriggeredResponse});
            $.ajax({url: tertiaryDataUrl, complete: this.handleTriggeredResponse});
        },
        handleTriggeredResponse: function(response) {
            this.set(response.data);
        },
        url: firstDataUrl
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to validate both single field and multiple field data from a
I would like to use single a href link to call different functions .
Question I would like to be able to use a single regex (if possible)
I would like to use Linq to Xml to get a single XElement from
What I would like to do: use a single container to load images. As
I would like to use the logout function from Django but not sure how
I would like to use a single haml/mustache template, like this: .foo %h2 {{title}}
I would like to use a single instance of QMenuBar to ease integration with
I would like to use a data list for showing the usernames and their
I would like to use curl, on the command line, to grab a url,

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.