Skip to content

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jun 4, 2025

Summary

This adds dependent/inverse_of options to has_many relations around the spree_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:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@mamhoff mamhoff requested a review from a team as a code owner June 4, 2025 07:39
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Jun 4, 2025
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.95%. Comparing base (db99cba) to head (04493b1).
Report is 7 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@tvdeyen tvdeyen left a 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

@tvdeyen tvdeyen added this to the 4.6 milestone Jun 4, 2025
@tvdeyen tvdeyen moved this to In Progress in Solidus Public Roadmap Jun 4, 2025
@mamhoff mamhoff force-pushed the foreign-key-inverse-of-product-taxons branch from 6a44e48 to dd9bb7a Compare June 6, 2025 10:44
Copy link
Member

@kennyadsl kennyadsl left a 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.


class AddFkToProductProperties < ActiveRecord::Migration[7.0]
def change
add_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@mamhoff mamhoff force-pushed the foreign-key-inverse-of-product-taxons branch from dd9bb7a to 50447f0 Compare June 18, 2025 14:38
mamhoff added 2 commits June 18, 2025 16:44
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.
@mamhoff mamhoff force-pushed the foreign-key-inverse-of-product-taxons branch 3 times, most recently from 5a63bcd to 1d6044f Compare June 19, 2025 13:49
mamhoff added 4 commits June 19, 2025 17:48
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.
@mamhoff mamhoff force-pushed the foreign-key-inverse-of-product-taxons branch from 1d6044f to 04493b1 Compare June 19, 2025 15:53
@tvdeyen tvdeyen merged commit acb9cc8 into solidusio:main Jun 20, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Solidus Public Roadmap Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
Development

Successfully merging this pull request may close these issues.

3 participants