Adding Sorbet Types to Models #2327
Insomniak47
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all,
I've been working on trying to get Sorbet typing into our DB Models as part of an initiative to improve the static typing in our codebase. We've written a tapioca compiler to handle the setters that get generated. Unfortunately we've hit a snag because of Sorbets requirements to know types statically - it complains about the use of
Sequel.Model(:thing)
because it is unable to statically determine the inheritance hierarchy Error Ref.We've tried to do a few workarounds to get things to co-operate but we're having some issues:
class MyModel < Sequel::Model
and moved table existence checks to be manual and disabledSequel::Model.require_valid_table
model_class.db.table_exists?(model_class.table_name)
It seems like the inherited hook in Sequel::Model reaches out the DB on set_dataset - since we use a number of DBs it means the main DB is getting hit for all tables based on the inferred names and then our validation is running afterwards. We're seeing a ton of sessions open to the PG instance and on our smaller, test instances it's causing issues.
The main questions I was hoping you could help me with are:
Sorry I know that Sequel wasn't really designed with the constraints of Sorbet in mind but we've found that the typing has been really positive for us so we'd like to try and do what we can and there's unfortunately no way for us to just silence the error on the sorbet side with an assertion - there is however an issue tracking it here.
Beta Was this translation helpful? Give feedback.
All reactions