codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

Limit to relate model

Open index23 opened this issue 11 years ago • 1 comments

Is there any way to limit database results for relate model? For example:

$this->some_model_one->with('some_model_two')->get('model_one_primary_key').

I want to limit number of 'some_model_two' results.

Model one has_many of some_model_two.

index23 avatar Feb 04 '14 11:02 index23

You should be able to limit the number of results by chaining ->limit(x) inside your call.

Line 762-769 of My_Model:

/**
* A wrapper to $this->_database->limit()
*/
    public function limit($limit, $offset = 0)
    {
        $this->_database->limit($limit, $offset);
        return $this;
    }

kbjohnson90 avatar Feb 04 '14 14:02 kbjohnson90