Class: JSONAPI::RemoveHasManyAssociationOperation
- Defined in:
- lib/jsonapi/operation.rb
Instance Attribute Summary collapse
-
#associated_key ⇒ Object
readonly
Returns the value of attribute associated_key.
-
#association_type ⇒ Object
readonly
Returns the value of attribute association_type.
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
Attributes inherited from Operation
Instance Method Summary collapse
- #apply(context) ⇒ Object
-
#initialize(resource_klass, resource_id, association_type, associated_key) ⇒ RemoveHasManyAssociationOperation
constructor
A new instance of RemoveHasManyAssociationOperation.
Constructor Details
#initialize(resource_klass, resource_id, association_type, associated_key) ⇒ RemoveHasManyAssociationOperation
Returns a new instance of RemoveHasManyAssociationOperation.
146 147 148 149 150 151 |
# File 'lib/jsonapi/operation.rb', line 146 def initialize(resource_klass, resource_id, association_type, associated_key) @resource_id = resource_id @associated_key = associated_key @association_type = association_type.to_sym super(resource_klass) end |
Instance Attribute Details
#associated_key ⇒ Object (readonly)
Returns the value of attribute associated_key.
144 145 146 |
# File 'lib/jsonapi/operation.rb', line 144 def associated_key @associated_key end |
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
144 145 146 |
# File 'lib/jsonapi/operation.rb', line 144 def association_type @association_type end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
144 145 146 |
# File 'lib/jsonapi/operation.rb', line 144 def resource_id @resource_id end |
Instance Method Details
#apply(context) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/jsonapi/operation.rb', line 153 def apply(context) resource = @resource_klass.find_by_key(@resource_id, context: context) resource.remove_has_many_link(@association_type, @associated_key) return JSONAPI::OperationResult.new(:no_content) rescue ActiveRecord::RecordNotFound => e raise JSONAPI::Exceptions::RecordNotFound.new(@associated_key) end |