我的模型有如下关系:Rails的:范围有过滤器嵌套属性
Building
有很多Room
S作很多Bed
S作许多Accommodation
S,
,我想呈现的所有Building
秒,但在日期范围内创建了Accommodation
。从其他答案我明白,我需要为Building
模型创建范围,但我无法理解如何过滤此范围内的嵌套属性。
编辑:
可以说我有Building
1,2和3。每个Building
都有它自己的Room
S的有Bed
S的有Accommodation
秒。可以说只有Building
1有一个Accommodation
在范围内。因此,返回的数据必须是:
Building 1
...
Room n
...
Bed n
Accommodation that is in range
Bed n+1
...
...
Building 2 (accommodation arrays in beds are empty since there are no accommodations that are in range)
...
Building 3 (accommodation arrays is beds are empty since there are no accommodations that are in range)
...
这只包括住宿创建日期在范围内的建筑物,但我只想过滤住宿并返回所有建筑物 –
@KudayarPirimbaev不幸的是,您的评论对我来说毫无意义。你能重述吗? –
可以说我有建筑物1,2,3,而建筑物1有1个住处在范围内,1个不在,其他建筑物根本没有。你的解决方案将返回建筑1与所有住宿,而我需要返回建筑1与范围和其他建筑物的住宿 –