Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 嵌套hasManyThrough性能_Mysql_Laravel_Eloquent - Fatal编程技术网

Mysql 嵌套hasManyThrough性能

Mysql 嵌套hasManyThrough性能,mysql,laravel,eloquent,Mysql,Laravel,Eloquent,我的数据库布局遇到问题。基本上,布局以以下方式呈现: - Community - - Each community has officers (Model `User`) - - Each community has participants (Model `User`) - Chat rooms (different section) - - each chat room has participants (Model `User`) - - each chat has officers,

我的数据库布局遇到问题。基本上,布局以以下方式呈现:

- Community
- - Each community has officers (Model `User`)
- - Each community has participants (Model `User`)

- Chat rooms (different section)
- - each chat room has participants (Model `User`)
- - each chat has officers, which are generated based on the participant's community's officers. This means: It's not hard-coded into a new table, instead, it should fetch the officers of the community, to which the participant (non-officer) belongs to.
我的奋斗目标是实现最后一部分,那就是军官可以进入。我现在的查询完全是一团糟,尤其是当前服务器的计划。考虑到代码很长,我将直截了当地说:

- Fetch chat rooms
- - fetch participants of each chat room
- - - fetch communities of each participant 
- - - - fetch officers of each community 
- - - - add these officers to a main array in the model
- - - - remove any duplicated officers 
现在,您可以看到,这是一种非常松散的获得结果的方法,而且它需要大量的性能。官员和非官员之间唯一相关的模式是社区


最好的方法是什么?

您如何看待创建新的桌面聊天室社区,您将在其中存储社区的聊天室。 该表将包含community\u id user\u id和chat\u room\u id列。 每次用户加入/离开聊天室时,在此表中添加/删除记录。
每当用户加入新社区或离开新社区时,您也必须修改此新表,但使用此方法,您可以通过简单的查询从chat_room_community中选择*,其中community_id=?

获取所有可供官员使用的聊天室,我确实想到了这一点,但随后需要更新两个表。添加/删除官员时的社区官员表和新的聊天室社区表。对于雄辩的标准来说,这不是多余的吗?了解JOIN。我确实想过,但我认为使用雄辩的模型是最佳实践?我是否应该在关系内部进行原始查询?