Skip to content

Commit

Permalink
Update to enable views working with SchemaEnforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcgarvey committed Dec 8, 2020
1 parent 8caa63c commit 005bd76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/view_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe "views" do
nickname_info.count.should eq 3
end

pending "works with SchemaEnforcer" do
it "works with SchemaEnforcer" do
AdminUser.ensure_correct_column_mappings!
NicknameInfo.ensure_correct_column_mappings!
end
Expand Down
6 changes: 6 additions & 0 deletions src/avram/model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ abstract class Avram::Model
setup(Avram::Model.setup_getters)
setup(Avram::Model.setup_column_info_methods)
setup(Avram::Model.setup_association_queries)
setup(Avram::Model.setup_view_schema_enforcer_validations)
setup(Avram::BaseQueryTemplate.setup)
setup(Avram::SchemaEnforcer.setup)
end
Expand Down Expand Up @@ -202,6 +203,11 @@ abstract class Avram::Model
schema_enforcer_validations << EnsureMatchingColumns.new(model_class: {{ type.id }})
end

macro setup_view_schema_enforcer_validations(type, *args, **named_args)
schema_enforcer_validations << EnsureExistingTable.new(model_class: {{ type.id }})
schema_enforcer_validations << EnsureMatchingColumns.new(model_class: {{ type.id }}, check_required: false)
end

macro setup_getters(columns, *args, **named_args)
{% for column in columns %}
{% db_type = column[:type].is_a?(Generic) ? column[:type].type_vars.first : column[:type] %}
Expand Down

0 comments on commit 005bd76

Please # to comment.