5

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?

risingfish
  • 354
  • 3
  • 9

1 Answers1

4

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.

Treffynnon
  • 21,365
  • 6
  • 65
  • 98
michaelward82
  • 4,706
  • 26
  • 40
  • This issue had me literally screaming from frustration. I think probably this convention that the first columns in the table must be called simply 'id' should be mentioned very early in the documentation. – Bjørn Otto Vasbotten Nov 09 '13 at 18:37
  • For the people that does not want to go over the bug description, the solution can be to jsut change the id column name to id OR to specify the column name using the id_column_overrides setting, eg: ORM::configure('id_column_overrides', array( 'customer' => 'customer_id', )); – adosaiguas Nov 13 '13 at 09:46