luckyframework / luckyframework/avram

undefined constant error when using incorrect association type

Open
#109 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Might be related to #13

When a model is defined with an incorrect association to another model (ie. `has_many` instead of `belongs_to`) the error is very confusing as all it tells you is `undefined constant : Model`.

Here is a code sample that should reproduce the issue:

```crystal
class TestModel < BaseModel
table :test_models do
name : String
belongs_to : OtherModel
end
end

class OtherModel < BaseModel
table :other_models do
name : String
belongs_to : TestModel
end
end
```

As you can see, either `TestModel` or `OtherModel` should have a `has_one` association instead of a `belongs_to`. This will generate the error `undefined constant OtherModel` and a very unhelpful trace.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Crystal model example with the incorrect belongs_to association and trace the association declaration handling that produces the undefined constant error. Confirm the current error path and determine how the diagnostic should identify the incorrect association type; done means the example reports a useful, specific error instead of only undefined constant OtherModel.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.