Customers
All of them
Venue.find(ID).customers.delete_all
Only without appointments
Venue.find(ID).customers.includes(:appointments).where( :appointments => { :customer_id => nil } ).delete_all
or
Venue.find(ID).customers.where('appointments_count = 0').delete_all
Without paid online appointments
Venue.find(ID).customers.joins('LEFT OUTER JOIN "appointments" ON "customers"."id" = "appointments"."customer_id"').where('"appointments"."paid_online_at" IS NULL').delete_all
Without future appointments
Venue.find(ID).customers.joins('LEFT OUTER JOIN "appointments" ON "customers"."id" = "appointments"."customer_id"').where('"appointments"."time" < (?)', DateTime.current).delete_all
Without future appointments and paid online appointments
Venue.find(ID).customers.joins('LEFT OUTER JOIN "appointments" ON "customers"."id" = "appointments"."customer_id"').where('"appointments"."time" < (?) AND "appointments"."paid_online_at" IS NULL', DateTime.current).delete_all
Appointments
Before specific date
Venue.find(ID).appointments.where('"time" < (?)', DateTime.current).delete_all
Not paid online
Venue.find(ID).appointments.where('"appointments"."paid_online_at" IS NULL').delete_all
Before specific date and not paid online
Venue.find(ID).appointments.where('"time" < (?) AND "appointments"."paid_online_at" IS NULL', DateTime.parse("2016-11-02")).delete_all