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

Support Composite Primary keys in ActiveRecordColumns compiler #1646

Merged
merged 2 commits into from
Sep 12, 2023

Conversation

gmcgibbon
Copy link
Member

Motivation

Support Active Record composite primary keys in ActiveRecordColumns compiler.

Implementation

I imagine using Rails edge may not be ideal, and if it isn't, we can look at merging this closer to when CPK is released. Due to how the compiler works, I would also consider renaming it to ActiveRecordAttributes instead.

Tests

The implementation inadvertently fixed a bug where the generated attribute methods don't include id when using a non-id primary key. Active Record always has an id method defined via https://github.com/rails/rails/blob/bc2892ab4557136a959e95c329c2dcc0133c7585/activerecord/lib/active_record/attribute_methods/primary_key.rb.

@gmcgibbon gmcgibbon requested a review from a team as a code owner September 7, 2023 17:48
Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

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

I think it's okay to move to Rails main. We currently test against it so that logic would have to to be replaced with Rails 7: https://github.com/Shopify/tapioca/blob/main/gemfiles/Gemfile-rails-main.

There are some unrelated failures this PR will have to fix due to Rails main. It could be worth doing that work in another PR.

@gmcgibbon gmcgibbon force-pushed the cpk_support branch 2 times, most recently from 47cec53 to e475ccf Compare September 8, 2023 04:29
Composite key ids are tuples consisting of multiple columns.
In Active Record, the primary key column is always referenceable via
id attribute methods.
@gmcgibbon
Copy link
Member Author

This build is green now, and the CPK test is conditionalized to only run on main for now.

@vinistock
Copy link
Member

The changes look good to me, but can we please test DSL generation on Core before merging? Just to be on the safe side.

@gmcgibbon
Copy link
Member Author

Done. The output looks correct to me, so I'm going to merge.

@gmcgibbon gmcgibbon merged commit 2fcd72d into main Sep 12, 2023
30 checks passed
@gmcgibbon gmcgibbon deleted the cpk_support branch September 12, 2023 01:55
@paracycle paracycle added the enhancement New feature or request label Sep 12, 2023
@shopify-shipit shopify-shipit bot temporarily deployed to production September 13, 2023 22:55 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants