我試圖創建範圍,將只返回父對象的限制對象:軌道4應用範圍的子對象
class BillingData
scope :apply_restrictions, -> (restricted_numbers) {
joins(billing_data: [:billing_data_lines]).where(billing_data_lines: {info_number: restricted_numbers })
}
end
並調用它像這樣:
BillingData.apply_restrictions(restricted_numbers)
這項工作或只是返回任何匹配的東西。我如何重構此範圍以返回主對象,但使用已過濾的Child_data_lines列表?