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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:56:48+00:00 2026-05-26T22:56:48+00:00

I have a bus model, which has a nested route model. class Busables.Models.Bus extends

  • 0

I have a bus model, which has a nested route model.

class Busables.Models.Bus extends Backbone.Model
  url: '/buses'
  defaults:
    route: new Busables.Models.Route()

Then I have an overall error view which listens to the error events of the bus model and it’s route.

class Busables.Views.Errors extends Backbone.View
  el: '#error-area'
  template: JST['shared/error']

  # model in this instance is a bus
  initialize: ->
    @model.get('route').bind 'error', this.routeError, this
    @model.bind 'error', this.busError, this

So, when the user submits a form on the page, I save an attribute of the bus, and send it to the server:

class Busables.Views.NewBus extends Backbone.View
  ...

  saveBus: (event) ->
    event.preventDefault()

    @model.save {
      seats: this.$('#bus_seats').val(),
    }, {
      success: (model, response) ->
        console.log "Success. The model and response: ", model, response
        window.location.href = "/buses/#{response.id}"
    }

So the question is, how do I trigger validation of the nested route while I’m saving the bus?

  • 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-05-26T22:56:49+00:00Added an answer on May 26, 2026 at 10:56 pm

    You’ll need to override the validate method on your Bus and have it call the validation for the nested route.

    The validate method is called any time your model is updated or being saved, giving you an opportunity to prevent invalid data from making it’s way in to your model or back to the server. If you return any value from validate method that is not falsy, then the validate method will prevent the save or attribute update.

    Bus = Backbone.Model.extend({
      validate: function(attrs){
        var invalidBus = false; // do your real bus validation here
    
        var route = this.get("route");
        var invalidRoute = route.validate(route.toJSON());
    
        return invalidBus || invalidRoute;
      }
    });
    
    Route = Backbone.Model.extend({
      validate: function(attrs){
        // do your route validation here
        // return an 'invalid' status
      }
    });
    

    I would also recommend looking at the Backbone-Relational plugin. It handles a lot of this for you, and chances are you’ll be re-writing code that is already available in that plugin, if you do this yourself.

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

Sidebar

Related Questions

Suppose I have 2 models Public class Bus extends Model{ @OneToMany(mappedBy=bus) private List<Passenger> passengers;
I have a table that has 3 columns representing the stops in a bus
I have a super class Vehicle and three classes that extend on it: Bus
I have a message bus, and a class subscribes many methods to the message
I have an application which models the electrical distribution of a system whereby if
I have a table filled with bus stops. Each stop has a line_id ,
I have tree models: Tours, buses and locations Tour have more buses, buses more
Intel's 32-bit processors such as Pentium have 64-bit wide data bus and therefore fetch
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a fairly simple domain model involving a list of Facility aggregate roots.

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.