-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add association between stores and shipping #2557
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Spree | ||
class StoreShippingMethod < Spree::Base | ||
belongs_to :store, inverse_of: :store_shipping_methods | ||
belongs_to :shipping_method, inverse_of: :store_shipping_methods | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateStoreShippingMethods < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :spree_store_shipping_methods do |t| | ||
t.references :store, foreign_key: { to_table: "spree_stores" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this syntax is valid. It fails under MySQL with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading more, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fails after
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that this is creating an FK from a bigint to a normal size int. Removed the FK entirely in in #2596 |
||
t.references :shipping_method, foreign_key: { to_table: "spree_shipping_methods" } | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the opposite of the direction that we should have for the "none means all" rule.
I'd rather have "shipping method with no store is available to all stores" not "a store with no shipping methods can use all shpiping methods"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently payment methods do the same
https://github.com/solidusio/solidus/blob/master/core/app/models/spree/payment_method.rb#L39-L42
I'm not really a fan of that either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the direction we use for most of these types of associations. (As you found with payment methods.)
I agree that it's confusing and I'm also not a fan of the "none means all" pattern we've adopted, but it's probably best to at least keep them consistent.