$types = new $Type;
if (!empty($foo1)) $types->where('foo1', $foo1);
if (!empty($foo2)) $types->where('foo2', $foo2);
$types->limit(10);
$results = $types->findAll();
import assign from 'lodash.assign'
let obj2 = assign({}, obj1)
$select = "SELECT type FROM tablepart"
$placeholders = [];
if (!empty($foo1) || !empty($foo2)) {
$select .= " WHERE ";
if (!empty($foo1) && !empty($foo2)) {
$select .= "foo1= :foo1 AND foo2 = :foo2";
$placeholders['foo1'] = $foo1;
$placeholders['foo2'] = $foo2;
} else if (!empty($foo1)) {
$select .= "foo1= :foo1";
$placeholders['foo1'] = $foo1;
} else {
$select .= "foo2= :foo2";
$placeholders['foo2'] = $foo2;
}
}
$stmt = $pdo->prepare($select);
$stmt->execute($placeholders);
$data = $stmt->fetchAll();