DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.04k stars 85 forks source link

Parent Class using sti_class prepend the class names #177

Closed omarsancas closed 1 month ago

omarsancas commented 2 months ago

I have this Base Class with sti_class

Module AnonymousModule
  class AnonymousClass < ApplicationRecord
    include AnonymousModule::CommonFunctionality

    prefixed_with :anonymous

    self.table_name = 'anonymous'

    self.inheritance_column = :work_country

    sig { params(type_name: String).returns(T.class_of(AnonymousClass)) }
    def self.find_sti_class(type_name)
      case type_name      
      when AnonymousService::COLOMBIA
        AnonymousModule::ColombiaClass
      else
        AnonymousModule::AnonymousClass
      end
    rescue NameError
      super
    end

And I validate a column emergency_contact with StoreModel

module Attributes
    module AnonymousClass
        class EmergencyContact
            include StoreModel::Model

            attribute :first_name, :string, default: ''
            attribute :last_name, :string, default: ''
            attribute :relationship, :string, default: ''
            attribute :phone_number, Attributes::ContactInfo::PhoneNumber.to_type

        end
    end
end

When the phone number is not valid the message error show AnonymousClass:ColombiaClass is invalid: Emergency contact Phone number is invalid. I only wants to show Emergency contact Phone number is invalid in the backend, I try to overwrite with a lamba strategy or a custom validator but only override the Emergency contact Phone number is invalid

DmitryTsepelev commented 2 months ago

Hello! What's the desired behavior you're looking for? 🙂

omarsancas commented 2 months ago

I have not found a way to just display Emergency contact Phone number is invalid because showing the parent class it's irrelevant for the end user. So I need to disable showing the parent class AnonymousClass:ColombiaClass is invalid: I hope to makes sense

omarsancas commented 1 month ago

I hope you're doing well. I wanted to follow up on the comment. I understand you might be busy

DmitryTsepelev commented 1 month ago

Hey hey, I was on vacation, and eventually will come back here, but things would be faster if I'd have a failing spec 🙂

omarsancas commented 1 month ago

I figure it out, this error is not related to store_model gem so I'm going to close this issue. Thanks for your support!