objection.js icon indicating copy to clipboard operation
objection.js copied to clipboard

query row based on some row exists in a related table

Open pokhiii opened this issue 2 years ago • 0 comments

Consider the following 3 tables:

  1. book_components

    id title
    1 chapter 1
    2 chapter 2
  2. file_versions

    id book_component_id file_id
    1 1 1
    2 1 2
    3 2 3
  3. files

    id title category
    1 med.xml converted
    2 req.xml source
    3 doc.xml source

Now I want to fetch all the book components for which at least on file exists with category converted exists. So, for minimal example shown above, the query should return the row from book_components where id = 1. Because for that there exists a file converted file in the files table (id = 1).

Is there a way to do this via Objection?

pokhiii avatar Aug 14 '22 18:08 pokhiii