Module: Cathode::Action::RequiresAssociation
- Included in:
- RequiresHasManyAssociation, RequiresHasOneAssociation
- Defined in:
- lib/cathode/action.rb
Overview
Raises an error if the action was defined on a resource whose parent doesn’t have an association to the resource
Instance Method Summary collapse
-
#after_resource_initialized ⇒ Object
Determines whether an expected association is present.
-
#association_keys ⇒ Object
Defines the possible associations as ‘:resources` (`has_many`) or `:resource` (`has_one`).
Instance Method Details
#after_resource_initialized ⇒ Object
Determines whether an expected association is present.
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/cathode/action.rb', line 138 def after_resource_initialized if parent.present? && !overridden? reflections = parent.model.reflections if association_keys.map { |key| reflections.include?(key) }.none? raise MissingAssociationError, end end super end |
#association_keys ⇒ Object
Defines the possible associations as ‘:resources` (`has_many`) or `:resource` (`has_one`)
130 131 132 133 134 135 |
# File 'lib/cathode/action.rb', line 130 def association_keys [ resource.name.to_s.singularize.to_sym, resource.name.to_s.pluralize.to_sym ] end |