codeigniter-base-model
codeigniter-base-model copied to clipboard
$has_many and get_all() returns relationship for first value only.
In function relate(){}
just before return $row;
you clear the $this->_with
variable by setting it back to an empty array. This causes the relationship to only fire on the first row returned, after which if(in_array($relationship, $this->_with){}
will not fire. Removing $this->_with = array();
from the end of the function causes it to fire properly on a $has_many
relationship.
My test case is:
class Image_model extends MY_Model(){
public $has_many = array( "image_description" );
}
class Image_description_model extends MY_Model {
public $belongs_to = array( "image" );
}
And inside the controller:
$data['images'] = $this->image_model->with('image_description')->limit( 50, 0 )->get_all();
@D-Bush thank you for pointing this out. I just ran into this exact issue, and another in fact that I posted a new issue for... but you helped me resolve this problem quickly, thanks!
Ah. A very good point. has_many
relationships are something I hadn't actually used myself yet so never noticed it. I'll get that fixed soon (unless someone else wants to?). Thanks for letting me know!
I was about to post this very same issue.