Skip to content

Wrapping subselects in ARRAY() #1047

@drew-r

Description

@drew-r

I have a subselect that returns multiple rows.
To get the values out of the DB, I need to wrap the subselect in ARRAY().

There doesn't seem to be a way to achieve this without writing a raw query.

My use case is only a small variation on example http://vincit.github.io/objection.js/#getting-count-of-relations
e.g

const tweets = await Tweet
  .query()
  .select(
    'Tweet.*',
    raw('ARRAY(?)', Tweet.relatedQuery('likers').select('id')).as('likerIds')
  );

console.log(tweets[4].likeIds);

Any advice @koskimas ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions