I don't know why that is happening. Here's some info that may help you solve the problem, though:
The acquire
method is part of Backbone.Semaphore
, which is a mixin that's used for queue and concurrency management within Backbone.Relational. The semaphore mixin is mixed into a few different classes, including the RelationalModel
.
The private _permitsAvailable
property only is accessed within the mixin itself, using this._permitsAvailable
. Your error message tells you that the error occurs, because this
is undefined. This can only ever happen when a method is executed with Function.call
or Function.apply
.
Edit: The issue seems to be that jQuery is trying to serialize the model by iterating each of it's properties, and if the property is a function, calling that function and serializing its return value. This is a no-go for Backbone models, because the data attributes aren't actually on the model object, but stored in the Model.attributes
property.
This problem should be easily fixed by converting the model object to a more serialization-friendly format using the Model.toJSON
method :
$.ajax(
url: 'save'
type: 'POST'
data:
project: MyApp.project.toJSON()
)
Quoting from the Model.toJSON documentation:
Return a copy of the model's attributes for JSON stringification. This can be used for persistence, serialization, or for augmentation before being sent to the server. The name of this method is a bit confusing, as it doesn't actually return a JSON string — but I'm afraid that it's the way that the JavaScript API for JSON.stringify works.
You must also make sure that includeInJSON
option in reverseRelation
for backbone-relational is set to false to avoid serializing the related models in your model.attributes
.