Plugin to Backbone.js to allow for model fixtures.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Plugin to Backbone.js to allow for model fixtures.

Model fixtures are a handy way to load local copies of data for your models. This is useful when creating models for services that are still in development or to do localized testing that is not dependent on a network connection.


Set the fixtures parameters when defining a Model or Collection.

var SomeModel = Backbone.Model.extend({
	// set flag to use fixtures for this model
	useFixtures: true,

	// set the fixtures path
	fixture: 'fixtures/path',

	// optional type for fixtures (defaut: json)
	fixtureType: 'json'

	// optional fixtures root to prepend to all fixtures calls (default: empty)
	fixtureRoot: 'some/root/path/'

Model calls will now load the fixtures path

var model = new SomeModel();

model.fetch(); // loads some/root/path/fixtures/path/read.json

// new model; // loads some/root/path/fixtures/path/create.json

// updated model; // loads some/root/path/fixtures/path/update.json

model.destroy(); // loads some/root/path/fixtures/path/delete.json

Use fixtures for all models

Fixtures can be turned on for all supported models by setting the global fixtures flag. This will override any locally set flag on the model definition. This is useful when loading an entire app locally.

Backbone.fixtures = true


Backbone.fixtures Boolean Set to true to load the fixture for all models that has a defined fixture path. Default false

Backbone.fixturesRoot String Root path to load fixtures from. All fixture paths will be prepended with this root path. This can be overrided on a per model basis. Default empty string

Model.prototype.fixture String Path to model fixture. This must be defined for fixtures to load. Default undefined

Model.prototype.useFixtures Boolean Set to true to load the fixture for the model. Setting this to true overrides the global Backbone.fixtures setting of false. Default false

Model.prototype.fixturesRoot String Root path to load model fixture from. Fixture path will be prepended with this path. Setting this overrides the global Backbone.fixturesRoot value. Default empty string.


To suggest a feature, report a bug, or general discussion: