Idiorm find_many () returns only one object

I’ve been playing with the idiom for several days now, and little by little I managed to get it to actually start executing requests. However, I come across something strange, and I can not understand. The find_many () function returns only one record, and it is always the last record in the database. For example, I make the following query through 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 make an equivalent query in idiorm, I 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?

+4
source share
1 answer

After investigation; It would seem that your table does not have an id column, or the id column does not contain unique values, or you configured Idiorm to use an invalid column instead of id .

Idiorm loops through the returned rows and assigns them to the array using id as the index / key. If id absent, 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, since duplicates will overwrite previous keys in the array.

You can see more on github bug along with suggested changes.

+3
source

Source: https://habr.com/ru/post/1502714/


All Articles