luckyframework / luckyframework/avram
#create! behavior not same as #upsert! when set a foriegn key id.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Please check following code:
```crystal
class Report < BaseModel
table do
belongs_to process_line : ProcessLine
end
end
```
```crystal
process_line_id = env.params.url["process_line_id"].to_i
SaveReport.create!(process_line_id: process_line_id) # no compile error.
```
```crystal
process_line_id = env.params.url["process_line_id"].to_i
SaveReport.upsert!(process_line_id: process_line_id) # compile failed.
# no overload matches 'SaveReport.new' with types process_line_id: Int32
```
I thought `create!` should failed as `upsert!` do, right?
Or both of them support use `int` instead? i prefer raise error
for now, we have to fixed it like this:
```crystal
process_line_id = env.params.url["process_line_id"].to_i64
SaveReport.upsert!(process_line_id: process_line_id) # no compile error
```
Contributor guide
Research direction
Start by reproducing the Report example with the Crystal create! and upsert! calls using an Int32 and an Int64 foreign-key value. Compare how each entry point validates or constructs the model; done should mean the behavior is consistent and the intended type-error behavior is covered by a regression test.
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