V
V
Veiwai2021-09-12 19:04:30
PostgreSQL
Veiwai, 2021-09-12 19:04:30

Postgres Sequlize how to filter data through linked table?

I have 2 tables with a many-to-many relationship.
post <-> category

@BelongsToMany(() => Category, () => PostCategories)
 categories: Category[];


How can I get posts containing the id of only the categories I need?

// Хочу получить посты только из категорий 2 и 3
where: {
        categories: {
          [Op.in]: [2, 3],
        },
},


Sequilize swears that ERROR [ExceptionsHandler] column Posts.categories does not exist

How do I write the query correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question