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
0
votes
1 answer

Why is all my data defaulting to NULL, while using Knex.js/Objection? I'm not passing useNullAsDefault at all

I'm not passing useNullAsDefault, and I've even tried using useNullAsDefault: false. const knex = Knex({ client: 'pg', connection: 'postgres://postgres:@localhost:5432/db_development', });
stephano
  • 162
  • 2
  • 11
0
votes
1 answer

How to use binding without using raw() method?

I am new to knexjs. Knexjs: Binding with raw() works great. Is it possible to use binding with SQL builder without using the raw() method? Thanks!
0
votes
1 answer

Knex query with join - works with .where but not with .whereRaw

I am using knex and objection.js to work with my postgres database. I have this query involving three different tables and different possible filters. The problem I have is when I do a left join and query with .whereRaw, I get the following error:…
Marie Pelletier
  • 417
  • 2
  • 4
  • 15
0
votes
1 answer

ObjectionJS - Group models in a data layer file

I have a NodeJS app running fastify with fastify-objectionjs. For tidiness, I'd like to group all models in a single file called _main.js, where I export an array of the models inside the models folder. Since the fastify-objectionjs registration…
GigiSan
  • 1,170
  • 2
  • 19
  • 30
0
votes
1 answer

Specifying that a column should just be inserted not upserted

I have some data i want to insert via insertGraph ala ModelName .query(trx) .insertGraph(data) problem is I have a guard with allowInsert that specifies which columns should be populated. I have a column holding a foreign key to…
IdiakosE Sunday
  • 112
  • 1
  • 8
0
votes
1 answer

unrelate() doesn't seem to be changing or deleting the join table

UserTagAnswer model: answer: { relation: Model.ManyToManyRelation, modelClass: sails.config.models.UserTagAnswerOptions, join: { from: 'usertaganswer.id', through: { from:…
bzupnick
  • 2,646
  • 4
  • 25
  • 34
0
votes
1 answer

How to access the transaction of the current context while extending QueryBuilder class in Knex

Im trying to extend the QueryBuilder of Knex.js. I want to modify the delete() method in order to delete the child elements of my Objection.js Model. Current code works well, but I want to support transactions in the new method: class…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
0
votes
2 answers

Is it wrong to require/import a class that is already imported higher up the inheritance chain?

I have an external library (Objection.js) that I'm using in my Node.js app. I created a base model class that extends Objection's Model class for my entity models: const { Model } = require('objection') class ModelBase extends Model { //…
AJ.
  • 16,368
  • 20
  • 95
  • 150
0
votes
1 answer

`leftJoin()` does not return the joined tables data with Objection ORM using Knex.js

leftJoin only returns the first tables data but not the second table when I use the Knex leftJoin() method with an Objection.js model. The same query works fine when I do it directly in the terminal with psql the query looks like this: const result…
Rennzie
  • 172
  • 2
  • 9
0
votes
1 answer

Knex returns DATETIME fields applying offset of my machine timezone

I have following row saved in timezone Europe/Madrid at database: dateA = '2019-03-26 15:00:00' dateB = '2019-03-26 14:00:00' When selecting the entry: let entry = this.query().findById(id) I get following values (console.log(entry)): { dateA:…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
0
votes
0 answers

ObjectionJs andWhereRaw is not a function with postgres and nodejs

I am trying to understand why I'm getting a TypeError: ____.andWhereRaw is not a function using ObjectionJs with Postgres and how to resolve this error. const { Model } = require('objection') // Website Table exports.up (knex, Promise) => { return…
0
votes
1 answer

knex missing table name from query

I have a NodeJS server that runs Express and SQLITE. When I do: const knexx = await knex('Users') .where({id: user.id}) .update({ password: pwhashed }).toString() console.log(knexx) Somehow it prints: update set…
user6269972
  • 199
  • 1
  • 11
0
votes
0 answers

How to use "joinEager" along with raw sql query in Objection/Knex?

I have managed to write a raw query that allows me to get all products inside a category, even the products inside the category's sub categories all the way down the tree. I am using a raw query because I didn't know how to use objection's / knex…
faniva
  • 320
  • 2
  • 10
0
votes
1 answer

Mapping has many relations into array of items either in postgres or objection.js

I have a postgres database and am using Knex with Objection.js. This can either be postgres related or objection.js/knex related problem. I have two models, Account and Stat. Account has field "accountId" and Stat also has field "accountId". One…
Artsu
  • 23
  • 6
0
votes
2 answers

Objection.js ignoring validation of not recognized property type?

Im using this jsonSchema in my Objection model: static get jsonSchema() { return { type: 'object', required: ['firstName', 'lastName'], properties: { id: { type: 'integer' }, parentId: { type: ['integer',…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
1 2 3
18
19