Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiorm find_many() returns only one object

Tags:

php

idiorm

I've been playing with idiorm for a few days now, and little by little have managed to get it to actually start performing queries. I'm running into something a little odd though, and I can't figure it out. The find_many() function only returns one record, and it is always the last record in the database. For instance I do the following query via mysqli and I get all 16 users in my database:

// 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

Now, when I do an equivalent query in idiorm I only get user16, the last one in the database.

\ORM::configure('mysql:host=localhost;dbname=------');
\ORM::configure('username', '----');
\ORM::configure('password', '----');
\ORM::configure('logging', true);

$people = \ORM::forTable('users')->findMany();

Does anyone know why this is?

like image 812
risingfish Avatar asked Oct 02 '22 22:10

risingfish


1 Answers

After investigation; it would seem that either your table is missing an id column or your id column does not contain unique values or you have configured Idiorm to use an invalid column instead of id.

Idiorm loops over the rows returned and assigns them to an array, using the id value as the index/key. If there is no id value then only the last result is returned. If you have an id column that contains duplicate values, then you will get fewer results than you should as the duplicates will overwrite previous keys in the array.

You can see more over on the github bug, along with proposed changes.

like image 165
michaelward82 Avatar answered Oct 07 '22 22:10

michaelward82