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 array types in typed_store compiler #1924

Merged
merged 1 commit into from
Jun 17, 2024
Merged

Conversation

amomchilov
Copy link
Contributor

Motivation

Closes #1910

Implementation

Decide to refactor the #type_for method to take the whole ActiveRecord::TypedStore::Field object, instead of just its type_sym, because I would have needed to also pass in field.array. This way it can just access what it needs.

This has the nice benefit of moving the if field.null responsibility out of the decorate method.

Tests

I added tests for both array: true, null: true and array: true, null: false. I didn't assert the type of all the methods (since they're mostly the same), just the getter/setter (just like how other tests check them).

@amomchilov amomchilov added enhancement New feature or request feature labels Jun 14, 2024
@amomchilov amomchilov self-assigned this Jun 14, 2024
@amomchilov amomchilov requested a review from a team as a code owner June 14, 2024 19:00
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Thanks this looks like a good change. I have a few inline comments.

lib/tapioca/dsl/compilers/active_record_typed_store.rb Outdated Show resolved Hide resolved
lib/tapioca/dsl/compilers/active_record_typed_store.rb Outdated Show resolved Hide resolved
type = if field.array
# `null: false` applies to the array itself, not the elements, which are always nilable.
# https://github.com/byroot/activerecord-typedstore/blob/2f3fb98/spec/support/models.rb#L46C34-L46C45
# https://github.com/byroot/activerecord-typedstore/blob/2f3fb98/spec/active_record/typed_store_spec.rb#L854-L857

Choose a reason for hiding this comment

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

😮

Copy link

@ipvalverde ipvalverde left a comment

Choose a reason for hiding this comment

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

Thanks for quickly fixing that one!
I'm not seeing the tests though, did you miss a commit?

@amomchilov
Copy link
Contributor Author

@ipvalverde Nice catch. I lost it somehow, but was able to revive it back from my editor's local history.

Can you have a look and review? Cheers

Copy link

@ipvalverde ipvalverde left a comment

Choose a reason for hiding this comment

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

:shipit:

@amomchilov
Copy link
Contributor Author

amomchilov commented Jun 17, 2024

I ran these changes on core (cherry-picked in isolation, on top of the v0.14.3 version that core is currently using), and it type-checks without any changes needed:

https://github.com/Shopify/shopify/commit/36d05ee84d0084e452f644d2b07e01eb54795a8a

@amomchilov amomchilov merged commit 0c6796d into main Jun 17, 2024
30 checks passed
@amomchilov amomchilov deleted the Alex/typed_store-arrays branch June 17, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveRecord::TypedStore DSL compiler does not respect array: true for columns
3 participants