0
有沒有辦法預先考慮到活動的記錄查詢的現有order
部分?如何預先考慮到訂購與範圍條款
我在我的Location
模型中定義的以下關聯:
class Location < ActiveRecord::Base
has_many :location_parking_locations, -> { by_votes }
has_many :parking_locations, through: :location_parking_locations
end
在LocationParkingLocation
模型中,by_votes
範圍定義:
class LocationParkingLocation < ActiveRecord::Base
belongs_to :location
belongs_to :parking_location
scope :by_votes, -> { order("upvotes - downvotes ASC, upvotes + downvotes DESC, id ASC") }
end
我想一個範圍添加到ParkingLocation
模型它爲查詢添加了一個額外的範圍,但是我希望該範圍被添加到查詢的現有order
部分。範圍是這樣的:
class ParkingLocation < ActiveRecord::Base
has_many :location_parking_locations
has_many :locations, through: :location_parking_locations
scope :with_pending, -> { order(creation_pending: :desc) }
end
我希望打電話location.parking_locations.with_pending
,並取回parking_locations,通過投票有序的集合,但在收集開始的任意pending
停車位置。這可能嗎?