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

generated rbs for activerecord models does not respect serialize #227

Open
tlubz opened this issue May 31, 2022 · 1 comment
Open

generated rbs for activerecord models does not respect serialize #227

tlubz opened this issue May 31, 2022 · 1 comment

Comments

@tlubz
Copy link

tlubz commented May 31, 2022

The rbs generated for an ActiveRecord model that uses serialize :some_field, Array does not generate the correct RBS for it. ex

My situation is as follows:

schema.rb:

...
create_table "foos", id: :serial, force: :cascade do |t|
    ...
    t.text "photos"
    ...
  end
...

foo.rb:

class Foo  < ApplicationRecord
  serialize :photos, Array
  ...

it generates the following RBS in foo.rbs:

...
    def photos: () -> String?
    def photos=: (String?) -> String?
    def photos?: () -> bool
    def photos_changed?: () -> bool
    def photos_change: () -> [ String?, String? ]
    def photos_will_change!: () -> void
    def photos_was: () -> String?
    def photos_previously_changed?: () -> bool
    def photos_previous_change: () -> Array[String?]?
    def photos_previously_was: () -> String?
    def photos_before_last_save: () -> String?
    def photos_change_to_be_saved: () -> Array[String?]?
    def photos_in_database: () -> String?
    def saved_change_to_photos: () -> Array[String?]?
    def saved_change_to_photos?: () -> bool
    def will_save_change_to_photos?: () -> bool
    def restore_photos!: () -> void
    def clear_photos_change: () -> void
...

in this case, these should really be typed as Array[String]?, Array[Object]?, Array[untyped] or something similar...

e.g.

    def photos: () -> Array[String]?
    def photos=: (Array[String]?) -> Array[String]?
    def photos?: () -> bool
    def photos_changed?: () -> bool
    def photos_change: () -> [ Array[String]?, Array[String]? ]
    def photos_will_change!: () -> void
    def photos_was: () -> Array[String]?
    def photos_previously_changed?: () -> bool
    def photos_previous_change: () -> Array[Array[String]?]?
    def photos_previously_was: () -> Array[String]?
    def photos_before_last_save: () -> Array[String]?
    def photos_change_to_be_saved: () -> Array[Array[String]?]?
    def photos_in_database: () -> Array[String]?
    def saved_change_to_photos: () -> Array[Array[String]?]?
    def saved_change_to_photos?: () -> bool
    def will_save_change_to_photos?: () -> bool
    def restore_photos!: () -> void
    def clear_photos_change: () -> void
@trafium
Copy link

trafium commented Dec 2, 2024

Another similar case is when using Postgres array column, like this:

add_column :user, :photos, :string, array: true, default: []

generator produces String type signature, instead of Array[String].

Is there any way to manually override such cases, so that they would not be overwritten after running generators?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants