how to replicate **joins** in **db.query**?

this is a db.select query with a join to filter out only answers that are accepted
const queryAcceptedAnswers = (userId: number)=>
  db.select()
  .from(answersTable)
  .where(eq(answersTable.authorId, userId))
  .innerJoin(questionsTable, eq(answersTable.id, questionsTable.acceptedAnswerId))

let's say, there may be 2 accepted answers, thus this will be the response
"acceptedAnswers": [
    {
      "answers": {
        "id": 8,
        "content": "🤡🤡🤡",
        "authorId": 109352196,
        "questionId": 7,
        "createdAt": "2024-03-23T13:14:22.690Z",
        "useless": false
      },
      "questions": {
        "id": 7,
        "title": "какыфмыфвфывс",
        "content": "фывфывыфвывс",
        "authorId": 109352196,
        "createdAt": "2024-03-22T11:59:37.434Z",
        "category": "отношения",
        "acceptedAnswerId": 8
      }
    },
    {
      "answers": {
        "id": 6,
        "content": "aaa",
        "authorId": 109352196,
        "questionId": 8,
        "createdAt": "2024-03-23T11:46:38.130Z",
        "useless": false
      },
      "questions": {
        "id": 8,
        "title": "bruh",
        "content": "bruh222",
        "authorId": 109352196,
        "createdAt": "2024-03-22T11:59:37.992Z",
        "category": "отношения",
        "acceptedAnswerId": 6
      }
    }
  ]

How do I use joins in db.query api that will result in the same response or will filter out users accepted answers in a similar way? is it even possible with db.query? do i have to manage my relations in the schema?
Was this page helpful?