Questions tagged [objection.js]

An Object Relational Mapper (ORM) for Node.js

Formerly known as moron.js, objection.js is an Promise based ORM built on top of knex.js focusing on the loading and storing of javascript objects into relational databases, specifically the ones supported by knex.js.

It does not currently incorporate a query builder leaving that for knex.js.

Website: https://vincit.github.io/objection.js

Github repo: https://github.com/Vincit/objection.js/

284 questions
1
vote
0 answers

How to get the entire ObjectionJS object in a $beforeUpdate hook?

I have a model Invoice with a BelongsToOneRelation with Subscription, so when I want to make a subscription active I run something like await invoice.$relatedQuery('subscription', trx).update({status: "ACTIVE"}) I need to verify that there isn't…
Ebordon
  • 31
  • 6
1
vote
2 answers

ObjectionJS Relation Assocation ManyToMany Returns Empty Using withGraphFetched

Im missing something here, and its driving me nuts. This a very simple eager loaded query using withGraphFetched, I can see the related query being performed correctly in my console, even tested the query in my SQL editor and its correct, however…
Cheyne
  • 1,964
  • 4
  • 27
  • 43
1
vote
2 answers

Knex cannot run migrations because required configuration option "client" is missing

I'm evaluating Node.js 14.x for a new project. I'm testing Knex.js and Objection.js to interact with databases so I'm building a proof-of-concept project, but I'm running into some issues when trying to run the migrations (using npx knex --esm…
x80486
  • 6,627
  • 5
  • 52
  • 111
1
vote
0 answers

Postgresql Objection.js Model, need to join many to many to many

I have 3 tables Table1, Table2 and Table3. I need to connect Table1 and Table2 with ManyToMany relation. Then I need to connect Table1Table2 table with Table3 with ManyToMany relation. so I create Table1Table2 table with fields id, table1_id,…
1
vote
1 answer

Objection.js - Realtion with pivot table

i'm having hard times understanding how I should model many-to-many relationships in objections.js. Basically I have an app with an Users, Games and UsersScore tables. A account can have score in game. Tables are like this: USERS…
TgMrP
  • 32
  • 4
1
vote
1 answer

How do I insert a new entry into a table when another entry is created?

so I'm inserting req.body values into my Restaurant table with insertGraphAndFetch. On my Restaurant model I have a menu object with HasOneRelation. The menu table has a restaurantId, so what I'm trying to do is to create a menu entry with the…
user11910733
1
vote
1 answer

Objection.js add data from joined table to parent json

I have the following Objection.js models: Appointment: 'use strict' const { Model } = require('objection') class Appointment extends Model { // Table name is the only required property. static get tableName() { return 'appointment' } …
iDaniel19
  • 75
  • 7
1
vote
1 answer

How to join table one to many using objection js

I just used knex objection js. Currently I have a one to many table relationship as follows. Table user_groups: Column | Type | Collation | Nullable | Default | Storage | Stats target |…
Sukma Saputra
  • 1,539
  • 17
  • 32
1
vote
1 answer

.patch() do not saves the parameter to the database in Objection.js with Knex

I am creating Express API and I am using Objection.js as ORM with Knex.js I have created router for updating user password from the profile with 2 fields (old password and the new password),first it verifies the old password (protection from…
1
vote
0 answers

What is the most effective/efficient way to convert a complex Objection.js query to plain knex?

Objection.js is being removed from the application I'm working on. This leaves us with plain knex as query builder. I have now a complex objection query that eager loads a bunch of tables const adCampaign = await super.getById(id, { eager: `[ …
ilrock
  • 95
  • 4
1
vote
1 answer

Objection.js Extends Multiple Plugins

There are 2 plugins that I want to use, objection-password and objection-paginator but all plugins requires to extend some base classes, which is user class. How do I extend 2 classes in objectionjs ? My Code const Password =…
mandaputtra
  • 922
  • 3
  • 18
  • 36
1
vote
1 answer

Keep a relation map in Objection.js while removing the table

I'm developing a reddit-like site where votes are stored per-user (instead of per-post). Here's my relevant schema: content id | author_id | title | text ---|-----------|-------------|--- 1 | 1 (adam) | First Post | This is a test post by…
rasocbo
  • 35
  • 6
1
vote
2 answers

Objection JS & Postgres & Exporess returning 'TypeError: Cannot read property 'isPartial' of null' on many to many relation query

I am trying to relate table named 'products' to another table named 'tags'. I have a many to many table titled 'products_tags'. When running const product = await Product.relatedQuery('tags').findById(1); I receive the following error: TypeError:…
AmazeCPK
  • 11
  • 2
1
vote
1 answer

Get count from Objection.js query using withGraphJoined

I have a really simple query and I'm trying to get the count. const query = Product.query() .withGraphJoined('collections') .whereIn('collections.id', [1,3]); I tried resultSize(), which worked on other queries I made that didn't use…
Norbert
  • 2,741
  • 8
  • 56
  • 111
1
vote
1 answer

Objection.js How to use outer values in inner query?

I'm struggling with a somewhat more complex SQL Query which HAS TO BE in Objection.js. Below is the code so far const tagEntry = await Tag_overview.query() .where('playable') //the playable column is a boolean .whereExists( …
Hobbamok
  • 767
  • 1
  • 11
  • 21