@anephenix/objection-relations 0.0.17 → 0.0.18
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/README.md +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,32 @@ The helper function will do the following:
|
|
|
61
61
|
| ----- | ---------- | ----------- |
|
|
62
62
|
| User | users | user_id |
|
|
63
63
|
|
|
64
|
+
*NOTE*
|
|
65
|
+
|
|
66
|
+
For TypeScript files to resolve correctly in Objection.js, use the model directly instead of the name as a string:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { ObjectionRelation } from '@anephenix/objection-relations';
|
|
70
|
+
import Address from './Address';
|
|
71
|
+
|
|
72
|
+
class User extends Model {
|
|
73
|
+
static get tableName() {
|
|
74
|
+
return 'users';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static get relationMappings() {
|
|
78
|
+
const or = new ObjectionRelation({
|
|
79
|
+
subject: this.name,
|
|
80
|
+
modelPath: __dirname,
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
// This changes from 'Address' to Address
|
|
84
|
+
addresses: or.hasMany(Address),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
64
90
|
## Dependencies
|
|
65
91
|
|
|
66
92
|
- Node.js
|
package/package.json
CHANGED