[英]How do I define a one-to-one relationship over a one-to-many relationship in a relational database?
[英]How can I define this database relationship
我有3張桌子:
場地 :
id | name
地點 :
id | address | venue_id | city_id
城市 :
id | name | slug | display_name
一個場所有一個位置,一個位置屬於一個場所。
一個位置屬於一個城市,一個城市有很多位置。
現在,場地和城市之間有什么關系?
我如何基於過濾城市從場所獲取查詢,我的意思是在城市執行“ where”。
如何從城市模型中獲得所有場地?
使用HasManyThrough
關系:
class City extends Eloquent
{
public function venues()
{
return $this->hasManyThrough(App\Venue::class, App\Location::class);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.