j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

If fewer results are available than passed to limit(), empty elements appear #48

Closed pthomsen closed 11 years ago

pthomsen commented 12 years ago

Say I use the following:


$page_size = 100;
$page_number = 3;
$users = Model::factory('BlergUsers')
                 ->where('session_id', $session)
                 ->where('user_type',$user_type)
                 ->order_by_asc('id')
                 ->offset($page_size * $page_number)
                 ->limit($page_size)
                 ->find_many();

foreach($users as $user)
{
  $username = $user->name;
}

I get an array that is 100 elements long, no matter how many rows are really available.

Should there not just be the number of rows returned from the query?

Thanks, Per

j4mie commented 12 years ago

Hi,

Which database are you using? I'm not seeing this behaviour here, using SQLite. The limit isn't used when iterating through the results - Idiorm just returns all the results that have come back from the database, which is making me think it might be a DB issue perhaps..

pthomsen commented 12 years ago

I'm using mysql.

treffynnon commented 11 years ago

I am unable to replicate this issue using Paris with MySQL. If it persists please open a ticket on the Paris issue tracker supplying your full model class and an SQL schema dump for the relevant table.