Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set the created_manually flag to true for all customers that don't ha…
…ve any orders
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
db/migrate/20230525081252_update_created_manually_flag_on_customers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateCreatedManuallyFlagOnCustomers < ActiveRecord::Migration[7.0] | ||
class Customer < ApplicationRecord | ||
has_many :orders, class_name: "Spree::Order" | ||
acts_as_taggable | ||
end | ||
|
||
module Spree | ||
class Order < ApplicationRecord | ||
belongs_to :customer | ||
self.table_name = 'spree_orders' | ||
end | ||
end | ||
|
||
def change | ||
# We want to set the created_manually flag to true for all customers that don't have any orders | ||
Customer.where.not(id: customers_with_at_least_one_order) | ||
.update_all(created_manually: true) | ||
end | ||
|
||
def customers_with_at_least_one_order | ||
Spree::Order.pluck(:customer_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters