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
#options, #resource_klass, #transactional
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(resource_klass, options) ⇒ RemoveHasManyAssociationOperation
constructor
A new instance of RemoveHasManyAssociationOperation.
Constructor Details
#initialize(resource_klass, options) ⇒ RemoveHasManyAssociationOperation
Returns a new instance of RemoveHasManyAssociationOperation.
280 281 282 283 284 285 |
# File 'lib/jsonapi/operation.rb', line 280 def initialize(resource_klass, ) @resource_id = .fetch(:resource_id) @associated_key = .fetch(:associated_key) @association_type = .fetch(:association_type).to_sym super(resource_klass, ) end |
Instance Attribute Details
#associated_key ⇒ Object (readonly)
Returns the value of attribute associated_key.
278 279 280 |
# File 'lib/jsonapi/operation.rb', line 278 def associated_key @associated_key end |
#association_type ⇒ Object (readonly)
Returns the value of attribute association_type.
278 279 280 |
# File 'lib/jsonapi/operation.rb', line 278 def association_type @association_type end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
278 279 280 |
# File 'lib/jsonapi/operation.rb', line 278 def resource_id @resource_id end |
Instance Method Details
#apply ⇒ Object
287 288 289 290 291 292 |
# File 'lib/jsonapi/operation.rb', line 287 def apply resource = @resource_klass.find_by_key(@resource_id, context: @context) result = resource.remove_has_many_link(@association_type, @associated_key) return JSONAPI::OperationResult.new(result == :completed ? :no_content : :accepted) end |