Idiorm find_many() 只返回一个对象


Idiorm find_many() returns only one object

我已经玩了几天的成语了,一点一点地设法让它真正开始执行查询。不过我遇到了一些奇怪的事情,我无法弄清楚。find_many() 函数只返回一条记录,并且它始终是数据库中的最后一条记录。例如,我通过mysqli执行以下查询,并在数据库中获取所有16个用户:

// connection is just a singleton instance to manage DB connections    
$connection->getRawInstance()->getRawConnection()->query('select * from users'));
// The result of this is all 16 users

现在,当我在 idiorm 中执行等效查询时,我只得到 user16,即数据库中的最后一个。

'ORM::configure('mysql:host=localhost;dbname=------');
'ORM::configure('username', '----');
'ORM::configure('password', '----');
'ORM::configure('logging', true);
$people = 'ORM::forTable('users')->findMany();

有谁知道这是为什么?

经过调查;似乎您的表缺少id列,或者您的id列不包含唯一值,或者您已将 Idiorm 配置为使用无效列而不是 id

Idiorm 循环返回的行并将它们分配给数组,使用 id 值作为索引/键。如果没有id值,则仅返回最后一个结果。如果你有一个包含重复值的id列,那么你得到的结果将比你应该得到的少,因为重复项将覆盖数组中以前的键。

您可以在github错误以及建议的更改上看到更多信息。