-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require at least one column defined on models #706
Require at least one column defined on models #706
Conversation
src/avram/model.cr
Outdated
@@ -72,6 +73,7 @@ abstract class Avram::Model | |||
macro view(view_name = nil) | |||
{{ yield }} | |||
|
|||
validate_columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered moving this macro into the setup
list below but if I did that it would have added a layer to the error message that pointed at macro code so I thought this makes the error easier to understand
src/avram/model.cr
Outdated
@@ -147,6 +149,12 @@ abstract class Avram::Model | |||
) | |||
end | |||
|
|||
macro validate_columns | |||
{% if COLUMNS.empty? %} | |||
{% raise "#{@type} must define at least one column." %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the typical Try this...
example here too? Like column my_column : String
would be fine I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it to match the validate_primary_key
error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Fixes #699