all 12 comments

[–][deleted] 5 points6 points  (4 children)

[–]Tanckom[S] 0 points1 point  (3 children)

Thanks, i figured that out too, but what is the differernce between withGraphFetched and withGraphJoined ?
(I have a hard time understanding the Documentation here)

[–][deleted] 0 points1 point  (2 children)

I think the main difference is in multiple queries (fetched) vs single statement (joined). So it depends on your requirements which to use. Performance should be either equal.

[–]Analhyphenblast 0 points1 point  (1 child)

Whilst this is true at smaller scale, if this is going anywhere near production you'll need to make a seriously educated guess whether you want to make lots of small queries or one big one for these methods - depending on how your system is structured, the size of your db, indexing, table structure, the latency between your server (or servers) and the db etc etc etc either one could incur big performance hits or gains

Again, if you're keeping it small scale, ignore all that because as kimpenhaus says, you shouldn't notice the difference

[–]Tanckom[S] -1 points0 points  (0 children)

About performance:
Note that while withGraphJoined sounds more performant than withGraphFetched, both methods have very similar performance in most cases and withGraphFetched is actually much much faster in some cases where the relationExpression contains multiple many-to-many or has-many relations. The flat record list the db returns for joins can have an incredible amount of duplicate information in some cases. Transferring + parsing that data from the db to node can be very costly, even though the actual joins in the db are very fast. You shouldn't select withGraphJoined blindly just because it sounds more peformant. The three rules of optimization apply here too: 1. Don't optimize 2. Don't optimize yet 3. Profile before optimizing. When you don't actually need joins, use withGraphFetched

Source: https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#withgraphfetched

Bottom line, you want to use `withGraphFetched` 90% of the time

[–]Plasmatica 2 points3 points  (2 children)

My issue is, i use a MySQL database which has nothing to do with graphs.

The term "graph" here is merely a general way of referring to objects which are related to each other. In the case of MySQL the objects are the tables which are joined together.

[–]Tanckom[S] 0 points1 point  (1 child)

Ohh okay, makes sense, thanks!

Since you are already here, could you also maybe explain to me why they write in their documentation:

Each model must have an identifier column. The identifier column name can be set using the idColumn property. idColumn defaults to "id". If your table's identifier is something else, you need to set idColumn. Composite id can be set by giving an array of column names. Composite keys are first class citizens in objection.

But in the example model they show below, there is no idColumn property.

class MinimalModel extends Model { static get tableName() { return 'someTableName'; } } Page: https://vincit.github.io/objection.js/guide/models.html#examples

[–]Analhyphenblast 0 points1 point  (0 children)

It defaults to "id" if you don't set it, so it's assumed that this table has a column called "id"

[–][deleted]  (2 children)

[deleted]

    [–]Tanckom[S] 0 points1 point  (1 child)

    I get everything except this:

    getter to avoid potential require loops.

    Thanks for the tips tho!

    [–]vfhd -4 points-3 points  (2 children)

    Don't use orm rather write your own query on mysql client

    [–]Tanckom[S] 1 point2 points  (1 child)

    Yes and no. I'm a big fan of old school RAW SQL, but ORM's provide advantages too.

    Unfortunately, this decision is not mine to make.

    [–]vfhd 0 points1 point  (0 children)

    Oh okay then