In my Ruby on Rails project I have a Message model which has attribute direction as either 'incoming' or 'outgoing'. Another attribute for Message is body which represents the actual content of the message. I'm using rails 5.1.2.
Now, I want to select messages while excluding incoming messages whose body is in an array, say ['a','b','c'].
For example, if I have the following messages in my database:
{direction: 'outgoing', body: 'a'}
{direction: 'outgoing', body: 'b'}
{direction: 'outgoing', body: 'd'}
{direction: 'incoming', body: 'd'}
{direction: 'incoming', body: 'c'}
I want to only select the messages except the last one, i.e. {direction: 'incoming', body: 'c'}
I've tried
Message.where.not(["direction = ? and body != ?","incoming","['a','b','c']"]) This only returned me outgoing messages but the incoming message with body 'd' is missing.
Any suggestions? Thanks.