atk4 / data

Data Access PHP Framework for SQL & high-latency databases
https://atk4-data.readthedocs.io
MIT License
273 stars 46 forks source link

setLimit(1) not working #1010

Closed mkrecek234 closed 2 years ago

mkrecek234 commented 2 years ago

Steps to reproduce:

  1. Select any model and add some conditions which result in multiple records. Optionally also setOrder.
  2. Apply setLimit(1) to restrict to one record only
  3. Then tryLoadOne()

I get this error: Atk4\Data\Exception: Ambiguous conditions, more than one record can be loaded Code snippet:

$customermodel = new \Atk4\Data\Model\Customer($db);
$customermodel->addCondition(\Atk4\Data\Model\Scope::CreateOr(['phone', 'LIKE', '%'.$number.'%'], ['mobile', 'LIKE', '%'.$number.'%']));
$customermodel->setOrder(['id']);
$customermodel->setLimit(1);
$entity = $customermodel->tryLoadOne();

What should be expected: If there was minimum one entity matching the conditions, $entity should contain that (first) one, otherwise $entity == null.

mvorisek commented 2 years ago

interesting finding, strictly taken it is a bug, as model modelled with max. 1 record cannot contain more than one record :)

I belive the $customermodel->addCondition(...) in the repro code is not even needed (and technically the setOrder neither, although any matching record will be picked)