diff --git a/spec/granite/table/table_spec.cr b/spec/granite/table/table_spec.cr index f5ac8ee9..5b1312df 100644 --- a/spec/granite/table/table_spec.cr +++ b/spec/granite/table/table_spec.cr @@ -9,6 +9,10 @@ describe Granite::Table do it "sets the table name based on class name if not specified" do SongThread.table_name.should eq "song_thread" end + + it "strips the namespace when defining the default table now" do + MyApp::Namespace::Model.table_name.should eq "model" + end end describe ".primary_name" do diff --git a/spec/spec_models.cr b/spec/spec_models.cr index 63bed736..853b8baf 100644 --- a/spec/spec_models.cr +++ b/spec/spec_models.cr @@ -509,6 +509,12 @@ end column my_enum : MyEnum?, column_type: "TEXT", converter: Granite::Converters::Enum(MyEnum, String) end + class MyApp::Namespace::Model < Granite::Base + connection {{ adapter_literal }} + + column id : Int64, primary: true + end + {% if env("CURRENT_ADAPTER") == "pg" %} class ConverterModel < Granite::Base connection {{ adapter_literal }} diff --git a/src/granite/table.cr b/src/granite/table.cr index 7e605e23..25a960f0 100644 --- a/src/granite/table.cr +++ b/src/granite/table.cr @@ -45,7 +45,7 @@ module Granite::Tables def table_name : String {% begin %} {% table_ann = @type.annotation(Granite::Table) %} - {{table_ann && !table_ann[:name].nil? ? table_ann[:name] : @type.name.underscore.stringify}} + {{table_ann && !table_ann[:name].nil? ? table_ann[:name] : @type.name.underscore.stringify.split("::").last}} {% end %} end end