... | ... | @@ -5,16 +5,20 @@ We've made an abstract data model class, which individual models extend. Hopeful |
|
|
* `update`: for PUTing one object at a time. (implements jsdata update method)
|
|
|
* `destroy`: for DELETEing one object at a tiem. (implements jsdata destroy method)
|
|
|
|
|
|
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).subscribe()`
|
|
|
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()`
|
|
|
|
|
|
## JSData Models (Mappers)
|
|
|
* extend Record
|
|
|
* name
|
|
|
* endpoint
|
|
|
* for jsdata loadrelations you have to specify what relations to load ex) ` foo.loadrealations('barObj')`
|
|
|
* should we name our model services like BookModelService?
|
|
|
## JSData & Models (Mappers)
|
|
|
* the DataStore is set up in one single place, `.../service/store.ts`, and only that place
|
|
|
* look to `.../models/User.model.ts` as a model for model setup
|
|
|
* models import that store and interact with it to defineMapper or in the case of the abstract model, invoke methods on the store
|
|
|
* we make the empty class, which extends `Record` so that we get useful class names for records like `User` or `[User, User, User]` in the console
|
|
|
* _name_: this is how JSData keeps track of mappers internally, so that relations can be hooked up, etc. It would be nice if the class name could just use this name property, but alas the library does not seem to be written that way
|
|
|
* _endpoint_: the REST endpoint this model will use when we run CRUD operations
|
|
|
* loadRelations: in v3, you have to specify relations to load by the localField name, e.g. ` foo.loadrealations(['barObj'])`; loadRelations is a method available on an individual resource. See example below
|
|
|
* pagination: where it at? how it do?
|
|
|
|
|
|
* _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
|
... | ... | @@ -70,7 +74,7 @@ DataStore.defineMapper(name, { // 'Publisher' |
|
|
},
|
|
|
});
|
|
|
|
|
|
this.Book.readList().subscribe(books => {
|
|
|
this.Book.readList().then(books => {
|
|
|
|
|
|
// loadedBooks === [
|
|
|
// {
|
... | ... | |