Answer the question
In order to leave comments, you need to log in
Why are SQL queries so slow?
Hello.
The point is this. There was a code for the Laravel framework, the result of which was a whole bunch of inner joins. Here is the code itself:
$this->product = $this->product->where(function ($query) use ($option, $value) {
$i = 0;
foreach($value as $single_value){
if($i == 0){
$query->whereHas('options', function($query) use($option, $single_value){
$query->where('name', $option)->where('value', $single_value);
});
} else {
$query->orWhereHas('options', function($query) use($option, $single_value){
$query->where('name', $option)->where('value', $single_value);
});
}
$i++;
}
});
$this->product = $this->product->whereHas('options', function ($query) use ($option, $value) {
$i = 0;
foreach($value as $single_value){
if($i == 0){
$query->where(function($query) use($option, $single_value){
$query->where('name', $option)->where('value', $single_value);
});
} else {
$query->orWhere(function($query) use($option, $single_value){
$query->where('name', $option)->where('value', $single_value);
});
}
$i++;
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question