Skip to content

Instantly share code, notes, and snippets.

@mixmix
Last active August 29, 2015 14:11
Show Gist options
  • Save mixmix/1bd2241164c79b501fb0 to your computer and use it in GitHub Desktop.
Save mixmix/1bd2241164c79b501fb0 to your computer and use it in GitHub Desktop.
Storey.switch 'amc'
a = Account.current
suppliers = Supplier.where(account_number: 'BLA') + Supplier.where(account_number: 'HAINES')
supplier_ids = suppliers.map(&:id)
target_parts = Part.where supplier_id: supplier_ids ; p 'got'
parts_in_use = JobPart.select(:part_id).map(&:part_id).uniq
target_parts_in_use = target_parts.select {|p| parts_in_use.include? p.id } ; p 'got'
target_parts_in_use.count
target_parts_not_in_use = target_parts - target_parts_in_use ; p 'got'
target_parts_not_in_use.count
target_parts_in_use.each {|p| p.update_attribute(:active,false)}
#target_parts_not_in_use.destroy_all
# Part.where(id: target_parts_not_in_use.map(&:id)).destroy_all
Part.where(id: target_parts_not_in_use.map(&:id)).limit(200).find_each(batch_size: 50) do |p|
p.destroy ; print '.'
end
@mixmix
Copy link
Author

mixmix commented Dec 19, 2014

target parts in use:

[9, 10, 11, 12, 13, 14, 15, 16, 24770, 26135, 33402, 66585, 66586, 66588, 66589]

these belong to BLA or HAINES, but are attached to a job already. I've marked them as not active

@mixmix
Copy link
Author

mixmix commented Dec 19, 2014

to see the jobs involved:

parts = Part.where(id: [9, 10, 11, 12, 13, 14, 15, 16, 24770, 26135, 33402, 66585, 66586, 66588, 66589]) ; p 'done'

jobs = parts.map(&:jobs).flatten.map(&:id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment