Skip to content

Commit

Permalink
set the created_manually flag to true for all customers that don't ha…
Browse files Browse the repository at this point in the history
…ve any orders
  • Loading branch information
abdellani committed May 30, 2023
1 parent b872d06 commit ed2deb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_05_16_072511) do
ActiveRecord::Schema[7.0].define(version: 2023_05_25_081252) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down

0 comments on commit ed2deb3

Please sign in to comment.