Tabela: dict_groups
id | name |
---|---|
1 | pytania_latwe |
2 | pytania_trudne |
Tabela: dicts
id | dict_groups_id | question
---------------- | -------------------
1 | 1 | pytanie 1 jest
2 | 1 | pytanie 2
3 | 2 | pytanie 8
Jak zrobić teraz takie zapytanie :
SELECT d.question
FROM dicts d
JOIN dict_groups dc ON dc.id = d.dict_groups_id
WHERE d.name = 'pytania_latwe'
tylko w laravel
$dc4 = Dict::with(['group' => function($query) {
$query->where('name', 'pytania_latwe');
}])->get();
moja metoda GROUP w klasie DICT
public function group() {
return $this->hasOne('App\DictGroup', 'id', 'dict_group_id');
}
ale to mi wyciaga wszystkie 3 wartosci zamiast tylko id 1 i id 2 z tabeli dicts
Jak to zrobic ?