How do i construct a dynamic scope search given a variable-length array of elements to exclude, as in:
class Participant < ApplicationRecord
scope exclude_names, -> (['%name1%', '%name2%', '%name3%', ...]) {
where.not(Participant.arel_table[:name_search].matches('%name1%').or(
Participant.arel_table[:name_search].matches('%name2%').or(
Participant.arel_table[:name_search].matches('%name3%').or(
...
}
but done dynamically as the name_list is of variable length.
I suggest to use
does_not_matchmethod and accumulateANDconditions iterating through excluded names. You also don't need call explicitly class name inside the scope, because it is class methodAfter that you can call this scope
Of course you can use
ORlike in your question, in this case it will be like thisAfter that you can call this scope, compare with previous queries