Rails返回所有二级关联 [英] Rails returning all of second level association

查看:65
本文介绍了Rails返回所有二级关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前对三种模型感兴趣:地区,座位和用户。

I currently have three models that I am interested in: Region, Seat and User.

地区有很多座位,而座位有很多可用的用户。

Region has many seats and seats have many available users.

我想知道在Rails中最有效的方法是检索特定区域内座位的所有可用用户。

I'd like to know what is the most efficient way in Rails to retrieve all of the available users for the seats which sit under a particular region.

谢谢。

推荐答案

尝试:

User.joins(seat: :region).where(regions: { id: REGION_ID_HERE })

这篇关于Rails返回所有二级关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆