Ensure matching column message when missing Enum#908
Ensure matching column message when missing Enum#908stan-slas wants to merge 1 commit intoluckyframework:mainfrom
Conversation
jwoertink
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think this will help for sure, but I have a few questions. I'm not sure if it's always been the case, but add_belongs_to choices : Int32 wouldn't ever make sense. This would assume Int32 has a id method that would relate back to choices_id. We may want to think about just putting something more generic there. Any ideas?
Also Enums can technically be Int64 as well. Maybe there's a way we can detect if the Enum type is Int64?
| message += " Did you mean '#{best_match.colorize.yellow.bold}'?\n\n" | ||
| else | ||
| # Enum column are mapped to Int32 in the database layer | ||
| missing_attribute_type_hint = "#{missing_attribute[:name]} : #{missing_attribute[:type].sub("Enum", "Int32")}" |
There was a problem hiding this comment.
This is nice, but it's possible to define an Enum as Int64 as well. #856
There was a problem hiding this comment.
Coming back to this, we may eventually want to add all of the Int. Like if you had a Colors Enum that you wanted to be Int8 or maybe Int16. I'm not sure the best way to handle this just yet, but definitely having Int32 static in here may be an issue.
First PR here 👋
What
When we declare an Enum field in the models, it should be referenced as Int32 in the migration file (https://luckyframework.org/guides/database/models#using-enums).
The current message was instead suggesting to type it as Enum in the migration which doesn't work.
How it has been tested
I didn't assert the full message for brevity of UT on hint messages. I thought it may become too verbose for a not critical function but feel free to request if needed.
Example of full message