-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add dependent/inverse_of options to product-related models #6271
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 dependent/inverse_of options to product-related models #6271
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6271 +/- ##
=======================================
Coverage 88.95% 88.95%
=======================================
Files 860 860
Lines 18422 18422
=======================================
+ Hits 16387 16388 +1
+ Misses 2035 2034 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 like all of this
6a44e48
to
dd9bb7a
Compare
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'm all in for this, but if I got it correctly, this change might be breaking and require some preliminary work on the database before the migrations succeed.
Probably it's just a matter of being explicit about this possibility, I would not block the PR but let's talk about it.
core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb
Show resolved
Hide resolved
|
||
class AddFkToProductProperties < ActiveRecord::Migration[7.0] | ||
def change | ||
add_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false |
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.
Same here, if there are rows without these constraints respected, will the migration fail?
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.
Same as above.
dd9bb7a
to
50447f0
Compare
Variant property rules belong to the product, if the product goes, the property rules can go as well. For the master variant and the non-master variants, we specify to do nothing when deleting the product, because they will be deleted from the `variants_including_master` association.
When deleting a taxonomy, its root taxon will delete all taxons, so the taxons association does not have to do it. The has_many has the inverse for taxon already defined, so we won't define another inverse.
5a63bcd
to
1d6044f
Compare
This model belongs to a product, and is useless without it. Remove the `optional` property from the `belongs_to` declaration and add a foreign key. This will also delete useless variant property rules.
Entries in this join table are useless if either "arm" of the join is not present. Remove the `optional` property from the `belongs_to` declarations, add a foreign key constraint.
This is a join table, both values must be present and pointing to an entry in the correct table.
This join table needs both references to be pointing to valid records. A uniqueness index for the taxon id in this table is already present.
1d6044f
to
04493b1
Compare
Summary
This adds
dependent/inverse_of
options tohas_many
relations around thespree_products
table. It also adds some foreign key constraints for join models.Extracted from #6240 .
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: