@@ 396-405 (lines=10) @@ | ||
393 | * @throws EE_Error |
|
394 | * @throws RestException |
|
395 | */ |
|
396 | public function addRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
397 | { |
|
398 | list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
399 | // Add a relation. |
|
400 | $related_obj = $model_obj->_add_relation_to($other_obj,$relation->get_other_model()->get_this_model_name()); |
|
401 | return array( |
|
402 | 'success' => $related_obj === $other_obj, |
|
403 | 'related_obj' => $this->returnModelObjAsJsonResponse($related_obj) |
|
404 | ); |
|
405 | } |
|
406 | ||
407 | ||
408 | /** |
|
@@ 440-449 (lines=10) @@ | ||
437 | * @throws EE_Error |
|
438 | * @throws RestException |
|
439 | */ |
|
440 | public function removeRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
441 | { |
|
442 | list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
443 | // Remove the relation. |
|
444 | $related_obj = $model_obj->_remove_relation($other_obj, $relation->get_other_model()->get_this_model_name()); |
|
445 | return array( |
|
446 | 'success' => $related_obj === $other_obj, |
|
447 | 'related_obj' => $this->returnModelObjAsJsonResponse($related_obj) |
|
448 | ); |
|
449 | } |
|
450 | ||
451 | /** |
|
452 | * Gets the model objects indicated by the model, relation object, and request. |