Skip to content
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

Merged
merged 2 commits into from
Jul 14, 2021

Conversation

matthewmcgarvey
Copy link
Member

Fixes #699

CleanShot 2021-07-12 at 16 35 35@2x

@@ -72,6 +73,7 @@ abstract class Avram::Model
macro view(view_name = nil)
{{ yield }}

validate_columns
Copy link
Member Author

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

@@ -147,6 +149,12 @@ abstract class Avram::Model
)
end

macro validate_columns
{% if COLUMNS.empty? %}
{% raise "#{@type} must define at least one column." %}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CleanShot 2021-07-12 at 18 16 50@2x

Updated it to match the validate_primary_key error

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@matthewmcgarvey matthewmcgarvey merged commit 1e28358 into luckyframework:master Jul 14, 2021
@matthewmcgarvey matthewmcgarvey deleted the empty-views branch July 14, 2021 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrations don't like when a view model is empty
2 participants