Skip to content

Commit

Permalink
Merge branch 'relation-free-format' into 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lode committed Jan 17, 2018
2 parents e75477b + 297f2d8 commit 09cc3f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion src/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 09cc3f7

Please sign in to comment.