|
|
## Abstract CRUD class
|
|
|
We've made an abstract data model class, which individual models extend. Hopefully, this allows for easier data service replacement, if need be. Right now, the template implements JSData for data needs, which has additional explanation below. Here are the abstract class methods:
|
|
|
* `create`: for POSTing one object at a time. (implements jsdata create method)
|
|
|
* `read`: for GETing one object at a time. (implements jsdata find method)
|
|
|
* `update`: for PUTing one object at a time. (implements jsdata update method)
|
|
|
* `destroy`: for DELETEing one object at a tiem. (implements jsdata destroy method)
|
|
|
* `create`: for POSTing one record at a time. (implements jsdata create method); ARGS: (attrs [, options])
|
|
|
* `read`: for GETing one record at a time. (implements jsdata find method); ARGS: (id [, options])
|
|
|
* `readList`: for GETing a list of the first page of records of a model. (implements jsdata findAll method); ARGS: ([params] [, options])
|
|
|
* `readListPaged`: for GETing _all_ records of this model. (implements custom http request); ARGS: ([params])
|
|
|
* `update`: for PUTing one record at a time. (implements jsdata update method); ARGS: (id, [attrs] [, options])
|
|
|
* `destroy`: for DELETEing one record at a time. (implements jsdata destroy method); ARGS: (id)
|
|
|
|
|
|
So, if you look at the configuration of the UserService, it extends AbscractModelService. And in a component, we inject it into the constructor as `User: UserService`, and go to town like so: `this.User.read(id).then()`
|
|
|
So, if you look at the configuration of the UserService, it extends AbscractModelService. And in a component, we inject it into the constructor as `User: UserService`, and go to town like so: `this.User.read(id).then()`
|
|
|
Note: previous versions of JSData used the `bypassCache` jsdata option, but in v3 it is now `force`
|
|
|
|
|
|
## JSDATA bypassCache is no more. The new keyword is force
|
|
|
|
|
|
## JSData & Models (Mappers)
|
|
|
* the DataStore is set up in one single place, `.../service/store.ts`, and only that place
|
... | ... | @@ -21,6 +23,7 @@ So, if you look at the configuration of the UserService, it extends AbscractMode |
|
|
|
|
|
* _NOTE_: in an earlier version of this template, the CRUD methods took theJSData promise which resulted from the various methods employed and wrapped it in an Observable, in an attempt to follow the use of RxJS elsewhere in ng2. While this might serve a cool purpose on certain apps (merging streams coming from various sources for use in... something cool), that can definitely be implemented on a case by case basis, and we'll leave the promises alone for now.
|
|
|
|
|
|
|
|
|
#### JSData Relations Example, using JSData v3, JSDataHttpAdapter v3
|
|
|
##### Django Model
|
|
|
```python
|
... | ... | |