henk
henk

Reputation: 2838

How can I address columns of included tables in where clause?

I have the following select statement, with a not working where clause:

 Comment.findAll({
              where:{
               $or: {
                    id : {
                        $like: 11
                    },
                    'posts.id': {
                        $like: 23
                    },
                    'autors.id': {
                        $like: 2
                    }
                }
              },
              include: [{
                 model: Post,
                 attributes: [],
                 include: [{
                    model: Author,
                    attributes: []

                 }]
               }]
             })

In my where clause, I would like to address the columns of my included tables. For instance select where posts.id is like 1000. What is the appropriate syntax to achieve this?

As far as I know, using where within the include, is not what I want, because of the necessary $or

Upvotes: 0

Views: 153

Answers (1)

henk
henk

Reputation: 2838

I have found the solution:

Comment.findAll({
              where:{
               $or: {
                    id : {
                        $like: 11
                    },
                    '$post.id$': {
                        $like: 23
                    },
                    '$post.autor.id$': {
                        $like: 2
                    }
                }
              },
              include: [{
                 model: Post,
                 attributes: [],
                 include: [{
                    model: Author,
                    attributes: []

                 }]
               }]
             })

Upvotes: 1

Related Questions