@ember-data/model 4.12.0-alpha.2 → 4.12.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +42 -18
- package/addon/-private.js +2 -2
- package/addon/{has-many-26353d30.js → has-many-465843f4.js} +292 -583
- package/addon/has-many-465843f4.js.map +1 -0
- package/addon/index.js +1 -1
- package/addon-main.js +18 -15
- package/blueprints/model/HELP.md +26 -0
- package/blueprints/model/files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model/index.js +150 -0
- package/blueprints/model/native-files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model-test/index.js +33 -0
- package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +18 -0
- package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +15 -0
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +14 -0
- package/package.json +28 -22
- package/addon/has-many-26353d30.js.map +0 -1
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,31 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img
|
|
3
|
+
class="project-logo"
|
|
4
|
+
src="./ember-data-logo-dark.svg#gh-dark-mode-only"
|
|
5
|
+
alt="EmberData Model"
|
|
6
|
+
width="240px"
|
|
7
|
+
title="EmberData Model"
|
|
8
|
+
/>
|
|
9
|
+
<img
|
|
10
|
+
class="project-logo"
|
|
11
|
+
src="./ember-data-logo-light.svg#gh-light-mode-only"
|
|
12
|
+
alt="EmberData Model"
|
|
13
|
+
width="240px"
|
|
14
|
+
title="EmberData Model"
|
|
15
|
+
/>
|
|
16
|
+
</p>
|
|
3
17
|
|
|
4
|
-
|
|
18
|
+
<p align="center">Provides a Presentation Model for resource data in an EmberData Cache</p>
|
|
5
19
|
|
|
20
|
+
This package implements the EmberData Store's `instantiateRecord` and `teardownRecord` hooks
|
|
21
|
+
as well as configures an associated `SchemaService` implementation.
|
|
6
22
|
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
Models are defined as classes extending from `import Model from '@ember-data/model';` and the
|
|
24
|
+
attributes and relationships on these classes are parsed at runtime to supply static "schema"
|
|
25
|
+
to EmberData's SchemaService.
|
|
9
26
|
|
|
10
|
-
|
|
11
|
-
|
|
27
|
+
Resource data for individual resources fetched from your API is presented to the UI via instances
|
|
28
|
+
of the `Model`s you define. An instantiated `Model` is referred to as a `record`.
|
|
12
29
|
|
|
30
|
+
When we refer to the `ModelClass` as opposed to a `Model` or `Record` we are referring
|
|
31
|
+
specifically to the class definition and the static schema methods present on it.
|
|
13
32
|
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
When we refer to a `record` we refer to a specific class instance presenting
|
|
34
|
+
the resource data for a given `type` and `id`.
|
|
16
35
|
|
|
17
|
-
|
|
18
|
-
ember install @ember-data/model
|
|
19
|
-
```
|
|
36
|
+
### Defining a Model
|
|
20
37
|
|
|
38
|
+
*app/models/person.js*
|
|
39
|
+
```ts
|
|
40
|
+
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
|
|
21
41
|
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
export default class PersonModel extends Model {
|
|
43
|
+
@attr name;
|
|
24
44
|
|
|
25
|
-
|
|
45
|
+
@belongsTo('pet', { inverse: 'owners', async: false }) dog;
|
|
26
46
|
|
|
47
|
+
@hasMany('person', { inverse: 'friends', async: true }) friends;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
------------------------------------------------------------------------------
|
|
51
|
+
### modelName convention
|
|
30
52
|
|
|
31
|
-
|
|
53
|
+
By convention, the name of a given model (its `type`) matches the name
|
|
54
|
+
of the file in the `app/models` folder and should be lowercase, singular
|
|
55
|
+
and dasherized.
|
package/addon/-private.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Model } from "./has-many-
|
|
2
|
-
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-
|
|
1
|
+
import { M as Model } from "./has-many-465843f4";
|
|
2
|
+
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-465843f4";
|
|
3
3
|
import { getOwner } from '@ember/application';
|
|
4
4
|
|
|
5
5
|
/*
|