makeFindOne
makeFindOne
is a hook that lets you define special findOne
behavior.
It is a generator function that lets you return the function that will
actually be called when findOne
is called.
can.Model.makeFindOne: function(findOneData) -> findOne
Returns the external findOne
method given the implemented findOneData function.
Parameters
-
findOneData
{findOneData(params)}
findOne is implemented with a
String
, ajax settings object, or findOneData function. If it is implemented as aString
or ajax settings object, those values are used to create a findOneData function.The findOneData function is passed to
makeFindOne
.makeFindOne
should usefindOneData
internally to get the raw data for the request.
Returns
{function(params, success, error)}
Returns function that implements the external API of findOne
.
Use
When a user calls
MyModel.findOne({})
, the function returned bymakeFindOne
will be called. Here you can specify what you want to happen before the real request for data is made. Call the function passed infindOneData
withparams
to make the AJAX request, or whatever the external request for data normally does.makeFindOne
can be used to implement base models that perform special behavior, like caching, or adding special parameters to the request object.makeFindOne
is passed a findOneData function that retrieves raw data. It should return a function that when called, uses the findOneData function to get the raw data and convert it to a model instance with model.Caching
The following uses
makeFindOne
to create a baseCachedModel
:The following Todo model will never request the same todo twice: