diff --git a/examples/relationships.php b/examples/relationships.php index bf14fd6..d161cd8 100644 --- a/examples/relationships.php +++ b/examples/relationships.php @@ -82,6 +82,14 @@ $jsonapi->add_relation('one-by-one-neighbours', $ship1_resource, $skip_include=false, $type=jsonapi\resource::RELATION_TO_MANY); $jsonapi->add_relation('one-by-one-neighbours', $dock_resource, $skip_include=false, $type=jsonapi\resource::RELATION_TO_MANY); +/** + * custom + */ +$custom_relation = [ + 'data' => ['cus' => 'tom'], +]; +$jsonapi->add_relation('custom', $custom_relation); + /** * sending the response */ diff --git a/src/resource.php b/src/resource.php index 7477ac0..853c539 100644 --- a/src/resource.php +++ b/src/resource.php @@ -269,8 +269,10 @@ public function add_relation($key, $relation, $skip_include=false, $type=null) { if (is_array($relation)) { $this->primary_relationships[$key] = $relation; + return; } - elseif ($relation instanceof \alsvanzelf\jsonapi\resource) { + + if ($relation instanceof \alsvanzelf\jsonapi\resource) { // add whole resources as included resource, while keeping the relationship if ($relation->has_data() && $skip_include == false) { $this->add_included_resource($relation);