简体   繁体   English

如何定义此数据库关系

[英]How can I define this database relationship


I have 3 tables: 我有3张桌子:
venues : 场地
id | name

locations : 地点
id | address | venue_id | city_id

cities : 城市
id | name | slug | display_name

a venue hasOne location, a location belongsTo a venue. 一个场所有一个位置,一个位置属于一个场所。
a location belongsTo a city,a city hasMany locations. 一个位置属于一个城市,一个城市有很多位置。

now, what's the relation between a venue and a city ? 现在,场地和城市之间有什么关系?
how can I get queries from venue based on filtering city I mean execute "where" on city slug. 我如何基于过滤城市从场所获取查询,我的意思是在城市执行“ where”。
How can I get all venues from a city model? 如何从城市模型中获得所有场地?

Use a HasManyThrough relationship: 使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM