Questions tagged [lucid]

Lucid is the AdonisJS implementation of the active record pattern.

Lucid is the AdonisJS implementation of the active record pattern.

If you’re familiar with Laravel or Ruby on Rails, you’ll find many similarities between Lucid and Laravel’s Eloquent or Rails' Active Record.

Lucid documentation

62 questions
1
vote
0 answers

AdonisJs Lucid ORM subquery as column for client-side sort

I am wanting to move the ORDER BY part of my AdonisJs query into a column as a number so that when it's stored on the client-side in a Vuex store I have a "Ranking" for ordering. let posts = Post.query().where('processed', 1) posts = posts …
Michael Smith
  • 625
  • 1
  • 8
  • 19
1
vote
1 answer

How to load only existing preload data in adonis js

I am working in adonis js I have a relation between my category table and my dishes table but when i preload dishes it loads dishes which have empty relation as well const data = await Category .query() .preload('dishes',(builder)=>{ …
rahul modi
  • 31
  • 4
1
vote
0 answers

Adonis V5 Lucid - Conditional Query

In the following code I'd like to filter according to received filters. The thing is that each of the filters can be defined or not. I'm getting a error inside the Lucid If statements because filters.status and filters.departments can be undefined.…
yuridamata
  • 459
  • 1
  • 5
  • 13
1
vote
1 answer

AdonisJS 5, dynamically connect database

Hi used Adonis Js 5 with the new version. I have multiple database clients with the same database structure, can I create a new database connection without declaring the config at config/database.ts? it means I can create a connection on the fly.
1
vote
0 answers

Best practices to set null field in model with AdonisJS 5 / Lucid

I'm building an API using AdonisJS with PostgreSQL. Some of my entities have optional fields. For example: a user may or may not have a phone number. I'm having trouble deciding the best and most acceptable way to clear an optional field value (e.g.…
Ernani
  • 319
  • 1
  • 4
  • 18
1
vote
2 answers

Adonisjs How to cast boolean to false and true in a model instead of 0 or 1?

This is my table field (open) but in response, it returns 0 1 but I want true false instead of 0 1 I am using adonis MySQL table.boolean('open').notNullable().defaultTo(true).comment('true = open, false = close') const Model = use('Model') class…
1
vote
1 answer

How to get specific field from nested table relation in adonisjs

THIS IS MY CODE QUERY i want to get only some specific field from every table: const project = await Project.query() .where("user_id", user_id) .where('id', project_id) …
1
vote
1 answer

Can't add a new key to object inside an array

I am a newbie in TypeScript const conversations = await Conversation .query() .whereRaw("FIND_IN_SET(" + user_id + ", participants)") .orderBy("last_message_timestamp", "desc") …
Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130
1
vote
1 answer

Getting error while storing data in db using adonis

I am using below code to put my row details through post request in db but error is coming: (insert into `product` (`created_at`, `description`, `id`, `image`,`pages`, `title`, `updated_at`) values ('2021-02-14 02:44:52', 'sddsds', 12, 'image',…
1
vote
1 answer

AdonisJS 5 - preload model even if foreign key is null

I want to preload a model even if it have a null foreign key. I'll use the models from Adonis docs page to ilustrate: User and Profile. const user = await User.query().preload("profile") Simple as that! But in my case, if a user have the key…
tomrlh
  • 1,006
  • 1
  • 18
  • 39
1
vote
1 answer

Adonis-Js : Get a specifc number of Entities in relationship with another Entity

I need your help in Adonis-Js for loading an an entity with relationships. Here is my problem : I have two entities : Contact (belongsTo Contactgroup) Contactgroup (hasMany Contact) I want to make a request to get the list of Contactgroup with…
1
vote
1 answer

why in lucid, user.save() is not function?

I get row by findOrCreate() method and update verification_code. when i want use user.save() i get this error : user.save is not a function my code: let user = User.findOrCreate({mobile: mobile}); user.verification_code = await…
Farshid Rezaei
  • 751
  • 2
  • 10
  • 34
1
vote
1 answer

How to order Lucid Models results based on relation?

What I want is to order all Service model results based on a relation (that belongsTo the same ServiceCategory) like Laravel does, something like this: const services = await Service .query() .orderBy('categories.id', 'desc') .fetch() The…
Eleandro Duzentos
  • 1,370
  • 18
  • 36
1
vote
1 answer

Cannot update Datetime type value with Lucid in AdonisJS

I cannot update a datetime type value in a table. (VIGENCIA) I`m using AdonisJS and Lucid models, and MySQL, but no matter what i try it remains the same. Sorry for english second language. const user = await auth.getUser(); const pack = await…
1
vote
1 answer

How i can make a create() method using a instance of my model in adonis /node.js?

I'm trying to make a insert using Lucid Models. So, first i define my model in a const: const ClasseLivroHistorico = use('App/Models/ClassBookHistoric') This is my function that needs to create a new record: async…
bla
  • 995
  • 3
  • 11
  • 44