Method: Effective::Resources::Sql#sql_type
- Defined in:
- app/models/effective/resources/sql.rb
#sql_type(name) ⇒ Object
This is for EffectiveDatatables (col as:) Might be :name, or ‘users.name’
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/effective/resources/sql.rb', line 43 def sql_type(name) name = (name.kind_of?(String) ? name.split('.').first : name.to_s) return :belongs_to if belongs_to(name) # Skip using columns() cause we dont need to check for belongs_to column = columns.find { |col| col.name == name } if column.present? column.type elsif has_many(name) :has_many elsif has_one(name) :has_one elsif belongs_to_polymorphic(name) :belongs_to_polymorphic elsif has_and_belongs_to_many(name) :has_and_belongs_to_many elsif active_storage(name) :active_storage elsif name == 'id' && defined?(EffectiveObfuscation) && klass.respond_to?(:deobfuscate) :effective_obfuscation elsif name == 'roles' && defined?(EffectiveRoles) && klass.respond_to?(:with_role) :effective_roles elsif (name.ends_with?('_address') || name.ends_with?('_addresses')) && defined?(EffectiveAddresses) && (klass.new rescue nil).respond_to?(name) :effective_addresses elsif name.ends_with?('_id') :integer else :string end end |