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

ActiveRecord::TypedStore DSL compiler does not respect array: true for columns #1910

Closed
ipvalverde opened this issue May 28, 2024 · 2 comments · Fixed by #1924
Closed

ActiveRecord::TypedStore DSL compiler does not respect array: true for columns #1910

ipvalverde opened this issue May 28, 2024 · 2 comments · Fixed by #1924
Assignees
Labels
enhancement New feature or request feature good-first-issue Good for newcomers

Comments

@ipvalverde
Copy link

If you're using the ActiveRecord::TypedStore gem (reference) and set a column as being array: true, the generated rbi will not respect the array indication. Example:

class Shop < ActiveRecord::Base
  typed_store :settings do |s|
    s.string(:tags, array: true, default: [], null: false)
  end
end

### Generated RBI:

class Shop
  module StoreAccessors
    sig { returns(String) }
    def tags; end

    # ...
  end
end

The expected would be to have the columns that are defined as array to have their type wrapped in a T::Array type. So for the example above, I would expect the output to be:

class Shop
  module StoreAccessors
    sig { returns(T::Array[String]) }
    def tags; end

    # ...
  end
end
@andyw8
Copy link
Contributor

andyw8 commented May 28, 2024

Related: #1217

@amomchilov
Copy link
Contributor

Just confirming, the array: true attribute is already available in-memory, so can make use of that in our compiler, without needing to hook the .string method.

https://github.com/byroot/activerecord-typedstore/blob/2f3fb98e6506d4d97113e5d817264c22bf9837da/lib/active_record/typed_store/field.rb#L14

It should be accessible on the field, here:

field = store_data.fields.fetch(accessor)

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 good-first-issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants