Relational icon indicating copy to clipboard operation
Relational copied to clipboard

How do you tackle nested wheres

Open kapv89 opened this issue 11 years ago • 5 comments

things like where foo=1 and (where bar=0 or baz=0) ?

kapv89 avatar Jun 24 '13 18:06 kapv89

Using the Sql class as this:

$this->object->select('*')->from('table')->where($data[0])->and_($data[1])->or($data[2])->_()

Leads to:

"SELECT * FROM table WHERE (a = ? OR b = ?) AND (c = ? OR d = ?)"

That's from our unit tests: https://github.com/Respect/Relational/blob/develop/tests/library/Respect/Relational/SqlTest.php#L294

It is not currently supported on the Mapper though, just Respect\Relational\Db and Respect\Relational\Sql.

alganet avatar Aug 13 '13 12:08 alganet

This can be a new feature to the Mapper?

williamespindola avatar Oct 14 '13 07:10 williamespindola

How to use IN operation? SELECT * FROM table WHERE id IN (1,2,3,4,5)

amdrade avatar Nov 14 '15 19:11 amdrade

@amdrade

This can help you: https://github.com/Respect/Relational/blob/master/tests/library/Respect/Relational/SqlTest.php#L72-L78

felipecwb avatar Nov 17 '15 13:11 felipecwb

Thanks @felipecwb !!

amdrade avatar Jul 16 '17 16:07 amdrade