UnionOfRAD / lithium

li₃ is the fast, flexible and most RAD development framework for PHP
http://li3.me
BSD 3-Clause "New" or "Revised" License
1.22k stars 237 forks source link

BUG: Model::find() returns false instead of empty RecordSet #1365

Closed adamroyle closed 1 year ago

adamroyle commented 1 year ago

Add to tests/integration/data/DatabaseTest.php to see the bug in action.

public function testNoResultsWithLimitAndHasMany() {
    $galleries = Galleries::find('all', [
        'conditions' => [
            'name' => 'not found'
        ],
        'with' => 'Images',
        'limit' => 1, // comment out this line and the test passes
    ]);
    $this->assertEqual([], $galleries->to('array'));
}

The bug occurs when you include a hasMany association combined with a limit and no results are returned.

This is due to some conditions inside Database::read and Database::_queryExport.

I don't think this is a new bug, but it does exist in 2.0 as I tested it against the latest dev branch.

nateabele commented 1 year ago

Would you be interested in pairing on it?

adamroyle commented 1 year ago

See my PR above with the test and fix. I also had to change a few things to get the test suite to run on php 8.2 on my local machine, but I didn't include those in this PR

nateabele commented 1 year ago

Fixed by #1368.