avram
avram copied to clipboard
Empty enumerable (Enumerable::EmptyError)
I'm not sure if this is an actual bug, or just a bad error, but this error happens if you pass in params to an operation and there's no permitted keys.
class SaveUser < User::SaveOperation
permit_columns :name
end
# user:beepbeep=true
SaveUser.create(params) do |_,_|
end
Will need to track down where this is happening.
This is caused from this line
https://github.com/luckyframework/avram/blob/21345fd17faaa2a7b5d59777b86bbff67a860269/src/avram/save_operation.cr#L283
When we call insert, we use a RETURNING statement which should return a record, but I think if the insert fails, then nothing is returned, and we basically call [].first which raises this error. One option could be to rescue this error and re-raise a Avram::RecordInsertError or something...
Chances are, update has the same issue:
https://github.com/luckyframework/avram/blob/21345fd17faaa2a7b5d59777b86bbff67a860269/src/avram/save_operation.cr#L290