Repository URL to install this package:
|
Version:
1.0.0-pre.1 ▾
|
Adds JSON API support to Backbone models and collections
npm.kinetic-vision.com as its registry.npm install satin-relational --save to start to use! See examples below.You should have no issues with your client-side code when switching to this library from standard Backbone or Backbone-relational models. All Backbone model calls stay the same. This only acts an an adapter and serializer between native Backbone data structures and JSON:API specifications for API responses.
You must define a model type on all models that can be returned from your JSON:API.
// models/color-metric.js import { Model, HasOne } from 'satin-relational'; import PixelMetricModel from './pixel-metric'; export default Model.extend({ relations: [ { key: 'pixel_metric', type: HasOne, relatedModel: PixelMetricModel } ] }, { type: 'color_metrics', apiVersion: 'v1' });
import ColorMetricModel from 'models/color-metric'; var metricModel = ColorMetricModel.findOrCreate({ id: 1 }); metricModel.fetch({ include: ['pixel_metrics'] });
| Option | Type | Description |
|---|---|---|
include |
Array | An array of related model types to include [ 'child_model_type', ... ] |
fields |
Object | A hash of { modelType: [ 'field', 'names' ], ... } to limit the response to |
sort |
Array | A hash of [ { attribute: 'key_name', direction: 'asc' }, ... ] |
// collections/color-metric.js import { Collection } from 'satin-relational'; import ColorMetricModel from 'models/color-metric'; export default Collection.extend({ model: ColorMetricModel });
import ColorMetricCollection from 'collections/color-metric'; var colorMetricCollection = new ColorMetricCollection(); colorMetricCollection.fetch({ include:['pixel_metrics'] page: { offset: 10, limit: 5 } });
| Option | Type | Description |
|---|---|---|
include |
Array | An array of related model types to include [ 'child_model_type', ... ] |
fields |
Object | A hash of { modelType: [ 'field', 'names' ], ... } to limit the response to |
sort |
Array | A hash of [ { attribute: 'key_name', direction: 'asc' }, ... ] |
page |
Object | A hash of { offset: 0, limit: 0 } or { number: 0, size: 0 } depending on your server paginator setup |
filter |
Object | A hash of { modelType: { attribute: 'value', ... }, ... } |