How to get the rows that has two or more columns that meets the same condition with a searcher of a function field

Hello everyone,
I am trying to make a searcher function for a function field that gets the rows (actually, the ids) of a table where the fields meets the same condition
Each field of the table is a fields.Selection() that has only the option ‘yes’ and ‘no’.
The class related to that table is call by a One2Many of another class, so, of course has a field that is a Many2One that is called ‘name’ (the fk pointing to the pk).
On sql, the sentence I need and works is the next:

select t.name
from mytable t
where (field1 = 'yes')::int 
    + (field2 = 'yes')::int 
    + (field3 = 'yes')::int >= 2

I try to make something like that, but without success.

query0 = (myTable.select(myTable.name,
                 where=(True if (
                       (1 if cTCall.field1 =='yes' else 0)+
                       (1 if cTCall.field2 =='yes' else 0)+
                       (1 if cTCall.field3 =='yes' else 0)+
                      )>2 else False)))
cursor.execute(*query0)
result0 = cursor.fetchall()

Ofcourse, this gives me an error.

So, any help or tip will be really appreciated. Thanks

maybe:

where = GreaterEqual(Equal(t.f1, 'yes').cast('INTEGER') + Equal(t.f2, 'yes').cast('INTEGER') + Equal(t.f3, 'yes').cast('INTEGER'), 2)

You can see for other functions:

1 Like

You can write it using syntax sugar:

where = ((cTCall.field1 == 'yes').cast('INTEGER') + (ctCall.field2 == 'yes').cast('INTEGER') + (ctCall.field3 == 'yes').cast('INTEGER')) >= Literal(2)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.