[eluser]WanWizard[/eluser]
Are you sure you're seeing the plant's id?
$c->plant->get() will return $this, which is $c. So you're seeing the Category's id. If you have issues like this, var_dump() the entire object so know what your looking at.
What does work:
Code:
function search($value=‘Climbers’){
$c = new Category();
$c->where(‘slug’,$value)->get();
$c->plant->get();
foreach ($c->plant as $plant){
echo “$plant->id <br>”;
}
}
Or even quicker (because it only uses one query):
Code:
function search($value=‘Climbers’){
$p = new Plant();
$p->where_related_category(‘slug’,$value)->get();
foreach ($p as $plant){
echo “$plant->id <br>”;
}
}