Module: StoreModel::ActiveAdminCompatibility::ReflectionMethods
- Defined in:
- lib/store_model/ext/active_admin_compatibility.rb
Overview
Patch for StoreModel::NestedAttributes::ClassMethods to add reflection methods
Instance Method Summary collapse
-
#reflect_on_association(name) ⇒ StoreModel::ActiveAdminCompatibility::Reflection?
Returns reflection for the given association name.
Instance Method Details
#reflect_on_association(name) ⇒ StoreModel::ActiveAdminCompatibility::Reflection?
Returns reflection for the given association name. This provides compatibility with form builders like ActiveAdmin’s has_many. First checks if the attribute is a StoreModel collection type, and if so, returns a reflection for it. Otherwise, delegates to the original implementation for ActiveRecord associations.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/store_model/ext/active_admin_compatibility.rb', line 51 def reflect_on_association(name) # First check if this is a StoreModel attribute # Use attribute_types directly to get the type for the given attribute type = attribute_types[name.to_s] if type.is_a?(StoreModel::Types::ManyBase) && type.respond_to?(:model_klass) && type.model_klass # Return reflection for StoreModel collection attributes return StoreModel::ActiveAdminCompatibility::Reflection.new(name.to_sym, type.model_klass) end # Not a StoreModel attribute, try to call the original method for ActiveRecord associations super rescue NoMethodError # No super method exists (pure StoreModel class), return nil nil end |