Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Her-35-add-product_id-and-product_type-to-order #29

Merged
merged 19 commits into from
Jan 8, 2025

Conversation

dewi-anggraini
Copy link
Collaborator

HER-35 : Add :product_id and :product_type to Order

Issue

https://raquelanaroman.atlassian.net/browse/HER-35

Description

We would like to be able to associate an Order with multiple types of Products, not just Kits, so we would like to add a polymorphic relationship to the orders model

Acceptance Criteria
add_reference to orders for product that is polymorphic

Changes

generate migration to add product to order
updated Kit model, donation model, order model with some validation
updated orders controller

Review Checklist

  • [v] I have documented my code with code comments.

@dewi-anggraini
Copy link
Collaborator Author

before event model

Copy link
Collaborator

@mhope21 mhope21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just forgot an "s" that would cause an undefined error.

@@ -1,6 +1,7 @@
class Order < ApplicationRecord
belongs_to :kit
belongs_to :user
belong_to :product, polymorphic: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

belongs_to :product, polymorphic: true

Forgot the s.

@mhope21
Copy link
Collaborator

mhope21 commented Dec 16, 2024

I am not really sure what is going on with the test check. Maybe we will have to ask Raquel.

@dewi-anggraini dewi-anggraini force-pushed the HER-35-add-product_id-and-product_type-to-order branch from bd3c2e9 to 41611f2 Compare December 18, 2024 03:48
@mhope21
Copy link
Collaborator

mhope21 commented Dec 19, 2024

Now you need to get your tests to match your changes. Let me know if you need help.

Copy link
Collaborator

@mhope21 mhope21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a few changes. Also, there are a bunch of minor corrections in your checks that need to be made, spaces mostly. I updated the brakeman in the last merge with main. So if you update your working branch with the latest main and run bundle install, then your brakeman will update automatically. Let me if you have problems, we may be able to get together on the zoom channel so you can share your screen.

Copy link
Collaborator

@raquii raquii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to address the errors in your PR!

@@ -1,6 +1,7 @@
class Order < ApplicationRecord
belongs_to :kit
#belongs_to :kit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this instead of commenting out

Suggested change
#belongs_to :kit

Comment on lines 2 to 8
def up
# define the changes kit id into product id
Order.where.not(kit_id: nil).find_each do |order|
order.update(product_id: order.kit_id, product_type: "Kit")
end
remove_column :orders, :kit_id, :integer
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do not expect existing Order records as the app is not yet deployed, lets not include an update script in our migration.

Suggested change
def up
# define the changes kit id into product id
Order.where.not(kit_id: nil).find_each do |order|
order.update(product_id: order.kit_id, product_type: "Kit")
end
remove_column :orders, :kit_id, :integer
end
def change
remove_column :orders, :kit_id, :integer
end

Copy link
Collaborator

@mhope21 mhope21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Copy link
Collaborator

@trca831 trca831 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@raquii raquii self-requested a review January 8, 2025 18:46
@mhope21 mhope21 merged commit 2fb8a78 into main Jan 8, 2025
3 checks passed
@mhope21 mhope21 deleted the HER-35-add-product_id-and-product_type-to-order branch January 8, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants