Joins
You can use custom joins to narrow down which records are returned, even for relationships that are not defined in your mapping definitions.
$query = QueryBuilder::create()
->leftJoin(Policy::class, 'p2')
->on('p2.policyNo', '=', 'policyNo')
->and('p2.id', '>', 'id')
->and('p2.status', '=', Policy::STATUS_INFORCE)
->and('p2.modification', '=', 'CANCELLED')
->where('modification', QB::NOT_EQ, 'CANCELLED')
->and('p2.id', 'IS', null)
->buildSelectQuery();SELECT [...] FROM `policy`
LEFT JOIN `policy` `p2` ON `p2`.`policy_no` = `policy`.`policy_no`
AND `p2`.`id` > `policy`.`id`
AND `p2`.`status` = 'INFORCE'
AND `p2`.`modification` = 'CANCELLED'
WHERE `policy`.`modification` != 'CANCELLED'
AND `p2`.`id` IS NULL Last updated