You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ What objection.js gives you:
17
17
-**Simple and fun way to [fetch, insert, update and delete](https://vincit.github.io/objection.js/guide/query-examples.html) objects using the full power of SQL**
18
18
-**Powerful mechanisms for [eager loading](https://vincit.github.io/objection.js/guide/query-examples.html#eager-loading), [inserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-inserts) and [upserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-upserts) object graphs**
19
19
-**Easy to use [transactions](https://vincit.github.io/objection.js/guide/transactions.html)**
-**A way to [store complex documents](https://vincit.github.io/objection.js/guide/documents.html) as single rows**
23
23
@@ -36,18 +36,18 @@ What objection.js **doesn't** give you:
36
36
For simple things it is useful that the database schema is automatically generated from the model definitions,
37
37
but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things
38
38
to you. knex has a great [migration tool](https://knexjs.org/guide/migrations.html) that we recommend for this job. Check
39
-
out the [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts).
39
+
out the [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts).
40
40
41
-
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) available.
41
+
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts) available.
42
42
43
43
Check out [this issue](https://github.com/Vincit/objection.js/issues/1069) to see who is using objection and what they think about it.
Copy file name to clipboardExpand all lines: doc/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ What objection.js gives you:
19
19
-**Simple and fun way to [fetch, insert, update and delete](/guide/query-examples.html) objects using the full power of SQL**
20
20
-**Powerful mechanisms for [eager loading](/guide/query-examples.html#eager-loading), [inserting](/guide/query-examples.html#graph-inserts) and [upserting](/guide/query-examples.html#graph-upserts) object graphs**
21
21
-**Easy to use [transactions](/guide/transactions.html)**
-**A way to [store complex documents](/guide/documents.html) as single rows**
25
25
@@ -33,8 +33,8 @@ What objection.js **doesn't** give you:
33
33
For simple things it is useful that the database schema is automatically generated from the model definitions,
34
34
but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things
35
35
to you. knex has a great [migration tool](https://knexjs.org/guide/migrations.html) that we recommend for this job. Check
36
-
out the [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts).
36
+
out the [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts).
37
37
38
-
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) available.
38
+
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/main/examples/koa-ts) available.
39
39
40
40
Check out [this issue](https://github.com/Vincit/objection.js/issues/1069) to see who is using objection and what they think about it.
Copy file name to clipboardExpand all lines: doc/guide/contributing.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ When creating an issue there are couple of things you need to remember:
13
13
Answer the following questions: Which objection version are you using? What are you doing? What code are you running? What is happening? What are you expecting to happen instead? If you provide code examples (please do!), **use the actual code you are running**. People often leave out details or use made up examples because they think they are only leaving out irrelevant stuff. If you do that, you have already made an assumption about what the problem is and it's usually something else. Also provide all possible stack traces and error messages.
14
14
15
15
3.**If possible, provide an actual reproduction**
16
-
The fastest way to get your bug fixed or problem solved is to create a simple standalone app or a test case that demonstrates your problem. There's a file called [reproduction-template.js](https://github.com/Vincit/objection.js/blob/master/reproduction-template.js) you can use as a starting point for your reproduction.
16
+
The fastest way to get your bug fixed or problem solved is to create a simple standalone app or a test case that demonstrates your problem. There's a file called [reproduction-template.js](https://github.com/Vincit/objection.js/blob/main/reproduction-template.js) you can use as a starting point for your reproduction.
17
17
18
18
Please bear in mind that objection has thousands of tests and if you run into a problem, say with `insert` method, it doesn't mean that `insert` is completely broken, but some small part of it you are using is. That's why enough context is necessary. It's not enough to say, "insert fails". You need to provide the code that fails and usually the models that are used too. And let's say this again: **don't provide made up code examples!** When you do, you only write the parts you think are relevant and usually leave out the useful information. Use the actual code that you have tested to fail.
Copy file name to clipboardExpand all lines: doc/guide/getting-started.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ To use objection.js all you need to do is [initialize knex](https://knexjs.org/g
4
4
5
5
The next step is to create some migrations and models and start using objection.js. The best way to get started is to check out one of our example projects:
6
6
7
-
-[The minimal example](https://github.com/Vincit/objection.js/tree/master/examples/minimal) contains the bare minimum for you to start testing out things with objection.
7
+
-[The minimal example](https://github.com/Vincit/objection.js/tree/main/examples/minimal) contains the bare minimum for you to start testing out things with objection.
-[The koa example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) is a simple [koa](https://koajs.com) server. The `client.js` file contains a bunch of http requests for you to start playing with the REST API.
16
+
-[The koa example project](https://github.com/Vincit/objection.js/tree/main/examples/koa) is a simple [koa](https://koajs.com) server. The `client.js` file contains a bunch of http requests for you to start playing with the REST API.
Copy file name to clipboardExpand all lines: doc/guide/plugins.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,11 @@ A curated list of plugins and modules for objection. Only plugins that follow [t
16
16
17
17
-[objection-filter](https://github.com/tandg-digital/objection-filter) - API filtering on data and related models
18
18
-[objection-graphql](https://github.com/vincit/objection-graphql) - Automatically generates rich graphql schema for objection models
19
+
-[objectionjs-graphql](https://www.npmjs.com/package/objectionjs-graphql) - Automatically generates GraphQl schema for objection models compatible with Objection 3.x (Graph fetch support)
19
20
20
21
## Plugin development best practices
21
22
22
-
When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](/api/model/), [objection.QueryBuilder](/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/master/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/master/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters.
23
+
When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](/api/model/), [objection.QueryBuilder](/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/main/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/main/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters.
23
24
24
25
Mixin is just a function that takes a class and returns an extended subclass.
Copy file name to clipboardExpand all lines: doc/guide/relations.md
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,11 +134,36 @@ class Person extends Model {
134
134
}
135
135
```
136
136
137
-
## Require loops
137
+
## Require loops (non ECMAScript modules only)
138
138
139
139
Require loops (circular dependencies, circular requires) are a very common problem when defining relations. Whenever a module `A` imports module `B` that immediately (synchronously) imports module `A`, you create a require loop that node.js or objection cannot solve automatically. A require loop usually leads to the other imported value to be an empty object which causes all kinds of problems. Objection attempts to detect these situations and mention the words `require loop` in the thrown error. Objection offers multiple solutions to this problem. See the circular dependency solutions examples in this section. In addition to objection's solutions, you can always organize your code so that such loops are not created.
140
140
141
-
Solutions to require loops
141
+
If you are using [ECMAScript modules](https://nodejs.org/api/esm.html), circular imports are not a problem. You can just do:
142
+
143
+
```js
144
+
importAnimalfrom"./Animal.js";
145
+
146
+
classPersonextendsModel {
147
+
staticgettableName() {
148
+
return"persons";
149
+
}
150
+
151
+
staticgetrelationMappings() {
152
+
return {
153
+
pets: {
154
+
relation:Model.HasManyRelation,
155
+
modelClass: Animal,
156
+
join: {
157
+
from:"persons.id",
158
+
to:"animals.ownerId",
159
+
},
160
+
},
161
+
};
162
+
}
163
+
}
164
+
```
165
+
166
+
However if you are not using ECMAScript modules, solutions to require loops are:
0 commit comments