luckyframework / luckyframework/avram

Issues with Single Table Inheritance(STI)

Open
#617 2 comments 0 reactions 0 assignees View on GitHub
improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Hi guys,

I just started using Lucky for a hobby project & am facing an issue using STI, yes, a Rails dev :). I have a User model & I'm using it as a Base Class for another model, but it keeps throwing this error:

```
In lib/avram/src/avram/queryable.cr:200:21

200 | getter preloads = [] of Array(T) -> Nil
^
Error: instance variable '@preloads' of User::BaseQuery must be Array(Proc(Array(User), Nil)), not Array(Proc(Array(User), Nil))
```

The error is not very informative, and I have been stuck here, and any help would be appreciated :)

### user.cr
```ruby
class User < BaseModel
include Carbon::Emailable
include Authentic::PasswordAuthenticatable

table do
column email : String
column encrypted_password : String
column type : String
column name : String
column dob : Time?
column phone : String
column failed_logins : Int16
column status : String
column confirmation_token : String?
column confirmation_sent_at : Time?
column confirmed_at : Time?
column last_login_at : Time?
column last_signin_ip : String?
column password_reset_at : Time?
end

def emailable : Carbon::Address
Carbon::Address.new(email)
end
end
```

### admin.cr
```ruby
require "./user"

class Admin < User
end
```

Crystal 0.35.1
Lucky 0.25.0
Postgres 12.5

Thanks in Advance :)

Contributor guide

Open the contributing guide

Research direction

Start at lib/avram/src/avram/queryable.cr:200 and reproduce the error with the User and Admin STI definitions from user.cr and admin.cr. Compare the generated User::BaseQuery types and Crystal 0.35.1 behavior; done means the STI setup no longer fails with the reported preloads type error or reports a clear actionable cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgres
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.