From 32e274c1bf28307f7859a86ae4fbd130a57f575d Mon Sep 17 00:00:00 2001 From: matiasgarcia Date: Wed, 13 Jan 2021 10:34:22 -0300 Subject: [PATCH 1/3] Fix undefined method arel_table --- lib/static_models.rb | 15 ++++++++++++++- spec/static_models_spec.rb | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/static_models.rb b/lib/static_models.rb index b0b0ea7..c265847 100644 --- a/lib/static_models.rb +++ b/lib/static_models.rb @@ -36,7 +36,7 @@ def marked_for_destruction? def valid? true end - + # For compatibility with AR relations in ActiveAdmin and others. # Feel free to override this. def self.where(*args) @@ -112,6 +112,13 @@ def static_models_hashes(columns, hashes) raise ValueError.new if singleton_methods.include?(item.code) define_singleton_method(item.code){ item } end + + def arel_table + @arel_table ||= begin + table_name = self.to_s.split('::').map(&:underscore).map(&:pluralize).join('_') + Arel::Table.new(table_name, type_caster: ::StaticModels::FakeTypeCaster.new) + end + end end def find(id) @@ -202,6 +209,12 @@ def belongs_to(association, opts = {}) end end + class FakeTypeCaster + def type_cast_for_database(_attr_name, value) + value + end + end + class ValueError < StandardError; end class NotFoundError < StandardError; end end diff --git a/spec/static_models_spec.rb b/spec/static_models_spec.rb index b8ff1ad..4ea25a0 100644 --- a/spec/static_models_spec.rb +++ b/spec/static_models_spec.rb @@ -368,6 +368,10 @@ class ValidDog < ActiveRecord::Base dog.update(anything: dog) dog.should be_valid end + + it 'can be used in queries' do + expect(StoreDog.where(breed: Breed.collie).count).to be_zero + end end it "has a code accessor useful for validations" do From 352c1d380e344060d3328146d52bc292a793a09c Mon Sep 17 00:00:00 2001 From: matiasgarcia Date: Wed, 13 Jan 2021 10:36:19 -0300 Subject: [PATCH 2/3] Bump version number --- lib/static_models/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/static_models/version.rb b/lib/static_models/version.rb index 6e73f7f..963bb42 100644 --- a/lib/static_models/version.rb +++ b/lib/static_models/version.rb @@ -1,3 +1,3 @@ module StaticModels - VERSION = "0.4.8" + VERSION = "0.4.9" end From 3522d64c83c146666f07ef977dc4ec1c10605ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Hern=C3=A1n=20Garc=C3=ADa?= Date: Tue, 14 Jun 2022 10:51:53 -0300 Subject: [PATCH 3/3] Update version.rb --- lib/static_models/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/static_models/version.rb b/lib/static_models/version.rb index 963bb42..4f3fe68 100644 --- a/lib/static_models/version.rb +++ b/lib/static_models/version.rb @@ -1,3 +1,3 @@ module StaticModels - VERSION = "0.4.9" + VERSION = "0.5.0" end