From 1daaa357dc59935776e744d0248454160ce5088e Mon Sep 17 00:00:00 2001 From: Sergey Makridenkov Date: Tue, 5 May 2020 17:35:34 +0200 Subject: [PATCH] Fix read_attribute, see #396 (#397) * Fix read_attribute, see #396 * Fix typo Co-authored-by: George Dietrich --- spec/granite/columns/read_attribute_spec.cr | 10 ++++++++++ src/granite/columns.cr | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spec/granite/columns/read_attribute_spec.cr diff --git a/spec/granite/columns/read_attribute_spec.cr b/spec/granite/columns/read_attribute_spec.cr new file mode 100644 index 00000000..99fd40a7 --- /dev/null +++ b/spec/granite/columns/read_attribute_spec.cr @@ -0,0 +1,10 @@ +require "../../spec_helper" + +describe "read_attribute" do + # Only PG supports array types + {% if env("CURRENT_ADAPTER") == "pg" %} + it "able to read arrays" do + ArrayModel.new.read_attribute("i32_array").should be_nil + end + {% end %} +end diff --git a/src/granite/columns.cr b/src/granite/columns.cr index 7dd56218..348a08ac 100644 --- a/src/granite/columns.cr +++ b/src/granite/columns.cr @@ -145,7 +145,7 @@ module Granite::Columns self end - def read_attribute(attribute_name : Symbol | String) : DB::Any + def read_attribute(attribute_name : Symbol | String) : Type {% begin %} case attribute_name.to_s {% for column in @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) } %}