I have two tables. codes
and translations
.
codes table
id | name
---|------
1 | A99
translations table
id | code_id | language_code | copy
---|---------|---------------|------
1 |1 |en | Heart Disease
2 |1 |fr | Sning Nat
Code model
class Code
{
function translation() // for default lanuage
{
return $this->hasOne(Translation::class, 'code_id')->where('language_code', 'en);
}
}
Query
$codes = Codes::with(['translation' => function($query){
$query->where('copy', 'like', '%hltad la loq%');
}]);
This should return nothing, but it returns all Codes without translation.
In other words I just want this query behind the scene.
select codes.*, translations.copy from codes
inner join translations ON codes.id = translations.code_id
where translations.language_code='en'
and translations.copy like '%hltad la loq%'