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

ObjectionJS - Using "page" with "withGraphJoined"

I have a situation with withGraphJoined I have three tables Parent, Children and Friend. Parent has an One-To-Many relationship with Children and an One-To-One relationship with Friend and now i have a query await Parent.query() …
Almen Wong
  • 11
  • 1
1
vote
0 answers

Objection.js Syntax for INSERT INTO ... SELECT

The datastore is postgres. Can someone help in translating this to an Objection.js statement? It's easy to do this with two roundtrips, but ideally this would happen in one. INSERT INTO reports ( id, created_by, desc, …
Switch386
  • 454
  • 6
  • 19
1
vote
0 answers

Validate JSON against Objection model

I have a model like export default MyModel extends Model { id!: string; name!: string; age!: number; classes: Classes; public static tableName = 'users'; public static columnNameMappers = snakeCaseMappers(); static get…
AngularDebutant
  • 1,436
  • 5
  • 19
  • 41
1
vote
1 answer

Are nullable foreign keys possible with objectionjs/knex?

Maybe this is a simple fix, but I can't seem to figure out what I'm doing wrong here. I have a table that lists all the states Model: static get jsonSchema() { return { type: 'object', properties: { id: { type: 'integer' }, …
Muneeb
  • 27
  • 4
1
vote
1 answer

Writing a subquery for a relation's relation in Objection.js

I'm using version 2.2.15 at the moment and I'm following the relation subqueries recipe. I've outlined my models and their relationships towards the bottom. Currently, I'm fetching an event as well as it's post count using this query: const events…
mycellius
  • 568
  • 1
  • 5
  • 28
1
vote
0 answers

How to populate join table Objection.js

In learning how to use Objection.js, I am interested in learning how to implement a join table and populate it with the associated foreign keys. I made some progress but I'm not sure I am setting things up correctly. I created a smaller side project…
1
vote
0 answers

Knex filter on pre filtered request

I would like to achieve a request in which I can filter my results with where clauses and then apply others where but on the result of the first where return await UserModel.query() .withGraphFetched('roles') …
TPCRomain
  • 51
  • 2
1
vote
1 answer

Objection JS get extra properties from joined table + filter

I have the following Model: class Profile extends Model { ....................... static relationMappings = { finishers: { relation: Model.ManyToManyRelation, modelClass: Move, filter: (query) => query.select('move.id',…
trunks
  • 147
  • 2
  • 9
1
vote
1 answer

ObjectionJS - Insert one to many and update parent

Hello I'm a beginner with Objection js / Knex. I have an entity Item which relates to another entity Bag I want to insert an Item into a Bag and also update the weight of the bag according to the weight of the Item. Item class: id!: Id; …
WilsonPena
  • 1,451
  • 2
  • 18
  • 37
1
vote
2 answers

AND OR query with ObjectionJS, knex

SELECT * FROM EMPLOYEE WHERE AGE>40 AND (LOCATION='Chennai' OR NOT LOCATION='Agra'); How to write something similar to the above query statement in ObjectionJS/Knex ORM ?
Sree Sajai
  • 75
  • 7
1
vote
1 answer

Validate array of objects in Node

I have an array that looks something like this settings: [ { key: 'maxImageSize', value: '512' }, { key: 'maxFileSize', value: '2048' }, { key: 'searchResultsLimit', value: '10' }, ] I would like to validate the value of each key…
porone
  • 71
  • 1
  • 5
1
vote
1 answer

How to apply LOWER() to a ref in Objection

Im using a like where statement in my query like this: import { ref } from 'objection' // [...] query = query.where(ref('data.nested_data').castText(), 'like', `%${value}%`) And its working fine. The resulting query looks like this: WHERE…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
1
vote
1 answer

Additional join condition in Objection.js

I'm writing the following sort of query using Objection.js Node.js ORM: return Account.query() .alias('accounts') .whereIn('accounts.ID', accountIds) .where('accounts.DELETE_FLAG', 'N') .where('accounts.ISDELETED', false) …
Chad
  • 2,161
  • 1
  • 19
  • 18
1
vote
1 answer

Filter a many-to-many relation using a list of values

I'm using objection.js and knex.js for my RESTful API. In my database, I have three tables: products, characteristics and product_characteristics (join table with extra column named 'value'). So what I'm trying to do is to fetch all the products…
Sultan
  • 13
  • 4
1
vote
0 answers

Is there any methods in Objection.js for Leftjoin and RightJoin apart from knex querybuilder?

I am writing get service in node js api . We are using Objectionjs as ORM module. We have two Table 'RoleDescription' and 'Features'. Features is master table and RoleDescription is child table. here how it is linked: const { Model } =…