I searched google and looked at the docs, but I found no example of this.
I have this object with embedded children:
{
teacher: "Balthazar",
students: [
{ name: 'Wilfred', sibling: 'Cordelia' },
{ name: 'Mortimer', sibling: 'Arthur' },
{ name: 'Cordelia', sibling: 'Wilfred' },
{ name: 'Arthur' sibling: 'Mortimer' },
]
}
I want to find Balthazar
's students whose name
or sibling
is in ['Wilfred', 'Cordelia', 'foo']
. I got it to work this way:
criteria_a = balthazar.students.in(name: ['Wilfred', 'Cordelia'])
criteria_b = balthazar.students.in(sibling: ['Wilfred', 'Cordelia'])
criteria_a << criteria_b
But is there a cleaner way to chain criteria? I tried chaining, but it doesn't work. It produces an AND
intersection, not an OR
.
balthazar.students.
.in(name: ['Wilfred', 'Corderial'])
.in(sibling: ['Wilfred', 'Corderial'])
So, in plain speak, this query is name is in array **AND** sibling is in array
. But I want name is in array __OR__ sibling is in array
.