luckyframework / luckyframework/avram

Raise better error when through relationship is not defined

Open
#157 0 comments 3 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

```crystal
class Group < BaseModel
table :groups do
column title : String
# missing has_many memberships : Membership
has_many users : User, through: :memberships
end
end

class User < BaseModel
table :users do
column email : String
# missing has_many memberships : Membership
has_many groups : Group, through: :memberships
end
end

class Memebership < BaseModel
table :memeberships do
belongs_to group : Group
belongs_to user : User
end
end
```

When trying to join memberships, there's a compilation error:

```crystal
groups = GroupQuery.new.join_users

# undefined local variable or method 'inner_join_memberships' for GroupQuery
```

If you're not familiar with joins in Avram, it's not obvious what you're missing as everything seems to be in place. We should detect this and show a better error message that may help lead the user to the solution.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the GroupQuery.new.join_users example and inspect how Avram generates the through-relationship join methods. Trace the missing inner_join_memberships error and add detection that reports the absent relationship clearly; done when the example produces an actionable error instead of the undefined method compilation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.