Can't make query: select() and with()


#1

Hi again,

I’m trying to make this query work:

const userdata = await User.query()
  .where('id', auth.user.id)
  .select('id, username, last_visit')
  .with('group')
  .first()

It works without the .select() method:

  • When there is no select, all fields in the users database are loaded and the relationship with posts is also loaded.
  • But when I put the select in the query, the relation stops running (group returns undefined).

My question is: How can I use select (for the users table) and with (for the group relation) at the same time?


#2

Hello guys?


#3

try :

const userdata = await User.query()
  .where('id', auth.user.id)
  .select('id', 'username', 'last_visit')
  .with('group')
  .first()