|
| 1 | +### 0.9.x. ---> 0.10.0 - 24 June 2014 |
| 2 | + |
| 3 | +#### Breaking API changes |
| 4 | +##### #76 - Queries and filtering. |
| 5 | + |
| 6 | +###### Before |
| 7 | +```javascript |
| 8 | +DS.findAll('post', { |
| 9 | + query: { |
| 10 | + where: { |
| 11 | + name: 'John' |
| 12 | + } |
| 13 | + } |
| 14 | +}) |
| 15 | +``` |
| 16 | + |
| 17 | +###### After |
| 18 | +```javascript |
| 19 | +DS.findAll('post', { |
| 20 | + where: { |
| 21 | + name: 'John' |
| 22 | + } |
| 23 | +}) |
| 24 | +``` |
| 25 | + |
| 26 | +###### Before |
| 27 | +```javascript |
| 28 | +DS.filter('post', { |
| 29 | + query: { |
| 30 | + where: { |
| 31 | + name: 'John' |
| 32 | + } |
| 33 | + } |
| 34 | +}) |
| 35 | +``` |
| 36 | + |
| 37 | +###### After |
| 38 | +```javascript |
| 39 | +DS.filter('post', { |
| 40 | + where: { |
| 41 | + name: 'John' |
| 42 | + } |
| 43 | +}) |
| 44 | +``` |
| 45 | + |
| 46 | +###### Before |
| 47 | +```javascript |
| 48 | +// override how DS.filter handles the "where" clause |
| 49 | +DSProvider.defaults.filter = function (resourceName, where, attrs) { |
| 50 | + // return true to keep the item in the result set |
| 51 | + // return false to exclude it |
| 52 | +}; |
| 53 | +``` |
| 54 | + |
| 55 | +###### After |
| 56 | +```javascript |
| 57 | +// override how DS.filter handles the "where", "skip", "limit" and "orderBy" clauses |
| 58 | +DSProvider.defaults.filter = function (collection, resourceName, params, options) { |
| 59 | + // examine params and |
| 60 | + // decide whether to exclude items, skip items, start from an offset, or sort the items |
| 61 | + |
| 62 | + // see the [default implementation that ships with angular-data](https://github.com/jmdobry/angular-data/blob/master/src/datastore/index.js#L12) |
| 63 | + // overriding this method is useful when our server only understands a certain |
| 64 | + // params format and you want angular-data's filter to behave the same as your server |
| 65 | + |
| 66 | + // angular-data looks for the following fields: |
| 67 | + // - where |
| 68 | + // - skip (or offset) |
| 69 | + // - limit |
| 70 | + // - orderBy (or sort) |
| 71 | + |
| 72 | + // return the filtered collection |
| 73 | +}; |
| 74 | +``` |
| 75 | + |
| 76 | +###### Before |
| 77 | +```javascript |
| 78 | +DSHttpAdapter.defaults.queryTransform = function (resourceName, query) { |
| 79 | + // the second argument was the "query" field of the "params" passed in the DSHttpAdapter method |
| 80 | + // return the transformed query |
| 81 | +}; |
| 82 | +``` |
| 83 | + |
| 84 | +###### After |
| 85 | +```javascript |
| 86 | +// This is useful when you don't want to implement the filter method above |
| 87 | +// and instead rely on angular-data's expectation of where, skip, limit, orderBy, etc. |
| 88 | +// This transform is useful when you want to change the where, skip, limit, orderBy, etc. fields |
| 89 | +// into something your server understands. |
| 90 | +DSHttpAdapter.defaults.queryTransform = function (resourceName, params) { |
| 91 | + // the second argument is now the whole "params" object passed in the DSHttpAdapter method |
| 92 | + // return the transformed params |
| 93 | +}; |
| 94 | +``` |
0 commit comments