Welcome Guest, Not a member yet? Register   Sign In
Relationship puzzle
#2

[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>”;
    }  
}


Messages In This Thread
Relationship puzzle - by El Forum - 02-05-2012, 11:32 AM
Relationship puzzle - by El Forum - 02-05-2012, 04:17 PM
Relationship puzzle - by El Forum - 02-06-2012, 05:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB