多态关联查询 - Rails 5.1

Query in polymorphic association - Rails 5.1

我想查询多态关联:

@pois = Poi.where(poitable: Sleep.where(track_id: @track.id))

很好,可以了...我想添加第二个参数:

@pois = Poi.where(poitable: Sleep.where(track_id: @track.id)).or.where(poitable: Town.where(track_id: @track.id))

现在,我得到一个错误:"wrong number of arguments (given 0, expected 1)"

怎么了?

or 方法采用另一个 ActiveRecord 查询的参数

所以语法是:

Poi.where(poitable: Sleep.where(track_id: @track.id)).or(Poi.where(poitable: Town.where(track_id: @track.id)))