luckyframework / luckyframework/avram

SaveOperation fails to compile if using enum column defined within model

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

Description

I have a class `Order` and a column called `state` where the value is an enum `OrderState`. I originally had the enum defined within the model but upon creating and trying to use a SaveOperation it failed to compile with this error message

```
web | Showing last frame. Use --error-trace for full trace.
web | There was a problem expanding macro 'generate_create'
web |
web | Code in macro 'generate_save_methods'
web |
web | 2 | generate_create("id : Int64 | Avram::Nothing = Avram::Nothing.new,\ncreated_at : Time | Avram::Nothing = Avram::Nothing.new,\nupdated_at : Time | Avram::Nothing = Avram::Nothing.new,\nstate : OrderState | Avram::Nothing = Avram::Nothing.new,\nguest_token : String | Avram::Nothing | Nil = Avram::Nothing.new,\nuser_id : User::PrimaryKeyType | Avram::Nothing | Nil = Avram::Nothing.new,\n", "id: id,\ncreated_at: created_at,\nupdated_at: updated_at,\nstate: state,\nguest_token: guest_token,\nuser_id: user_id,\n", with_params: true, with_bang: true)
web | ^
web | Called macro defined in lib/avram/src/avram/needy_initializer_and_save_methods.cr:96:3
web |
web | 96 | macro generate_create(attribute_method_args, attribute_params, with_params, with_bang)
web |
web | Which expanded to:
web |
web | > 13 | created_at : Time | Avram::Nothing = Avram::Nothing.new,
web | > 14 | updated_at : Time | Avram::Nothing = Avram::Nothing.new,
web | > 15 | state : OrderState | Avram::Nothing = Avram::Nothing.new,
web | ^---------
web | Error: undefined constant OrderState
```

This is from version 1.0.0-rc1

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with an Order model whose state column uses an enum defined inside the model, then inspect lib/avram/src/avram/needy_initializer_and_save_methods.cr around generate_create and generate_save_methods. Confirm the compiler error and determine whether the SaveOperation can compile with the nested enum; done means the shown model builds successfully without an undefined constant OrderState 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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.