-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6552 from Matt-Yorkley/adjustments-order-association
[Adjustments] Associate all adjustments with an order
- Loading branch information
Showing
6 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,26 @@ | ||
class AddOrderToAdjustments < ActiveRecord::Migration | ||
def up | ||
class Spree::Adjustment < ActiveRecord::Base | ||
belongs_to :adjustable, polymorphic: true | ||
belongs_to :order, class_name: "Spree::Order" | ||
end | ||
class Spree::LineItem < ActiveRecord::Base | ||
belongs_to :order, class_name: "Spree::Order" | ||
end | ||
|
||
add_column :spree_adjustments, :order_id, :integer | ||
|
||
# Ensure migration can use the new column | ||
Spree::Adjustment.reset_column_information | ||
|
||
# Migrate adjustments on orders | ||
Spree::Adjustment.where(order_id: nil, adjustable_type: "Spree::Order").find_each do |adjustment| | ||
adjustment.update_column(:order_id, adjustment.adjustable_id) | ||
end | ||
|
||
# Migrate adjustments on line_items | ||
Spree::Adjustment.where(order_id: nil, adjustable_type: "Spree::LineItem").includes(:adjustable).find_each do |adjustment| | ||
adjustment.update_column(:order_id, adjustment.adjustable.order_id) | ||
end | ||
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
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
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