Niclas Schumacher Sat Nov 19 09:52:25 -0500 2011

Subject: Limit on include

Hallo guys. I've just started using php.activerecords for building my site with codeigniter.
And ive made the $belongs_to and $has_many that coresponds to the database design.
But when i pull something out, i'd like to be able to have a limit on the includes because sometimes i want 7 images, or 25 images. But as fare as i know i can only limit on the specefication, for an example at the images in the following code:

class Blogger extends ActiveRecord\Model {
static $belongs_to = array(
static $has_many = array(
array('questions', 'through' => 'bloggersquestions'),
array('images', 'order' => 'dated asc', "limit" => 7)
But id like to be able to do the limit on this string :
$array['blogger'] = Blogger::find_by_username($this->uri->segment(3), array('include' => array('images','bloggersquestions','questions')));
How can i limit how many records of a relations i want, in the individual querys?

Mikkel Schmidt Sun Nov 20 00:52:25 -0500 2011

I think the only way to do that right now is by using the SQLBuilder and find_by_sql. That's how i solved a similar problem.

It would be nice, and infinitely flexible if the include array could take options aswell, although it would further complicate the options arrays. Like this:

 1 Blogger::find('all', 
 2     array(
 3         'include' =>
 4             'images' => array(
 5                 'limit' => 25,
 6                 'conditions' => array(
 7                     'width' => '200px'
 8                 )
 9             ),
10             'bloggersquestions',
11             'questions'
12         )
13     )
14 );

Doesn't seem like it would be hard to implement, though i fear there will be side effects. I might have a go at it soon.