To make it clear - eager loading (with()
method) does not join anything, but runs another query per each loaded relation with WHERE id IN
clause.
Change those relations as they are completely incorrect:
// Let's call methods snakeCased just for clarity and sticking to the convention
// and singular or plural depending on what is returned
class Highlight extends Eloquent
{
function service(){
return $this->belongsTo('Service'); // returns single Model
}
function page(){
return $this->belongsTo('Page'); // same as above
}
}
class Service extends Eloquent
{
function highlights(){
return $this->HasMany('Highlight'); // returns Collection of Models
// you can have hasOne instead, depending on your app
}
}
class Service extends Eloquent
{
function highlights(){
return $this->hasMany('Highlight'); // again Collection
}
}
Then you call it:
// returns Collection, so let's call it plural:
$highlights = Highlight::where('id', $id)->with(array('service','page'))->get();