Skip to content
Snippets Groups Projects

Initial Anchor support for recursive relations (OTO only)

Merged James Walker requested to merge anchor-recursive-relations-oto into master
3 files
+ 128
28
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -76,12 +76,26 @@ final class AnchorHydrationSet {
}
// Hydrate relations in the record
foreach ($this -> resource -> relations() -> members() as $rel) {
if ($record -> containsRelation($rel)) {
$this -> hydrateRelation($rel, $record);
}
}
$this -> hydrateRecordRelations($this -> resource, $record);
}
}
/**
* Hydrate a record's relations from a given Anchor resource.
*
* This recurses into the resource's own relations.
*/
protected function hydrateRecordRelations(
AnchorResource $resource,
AnchorRecord $record) : void {
foreach ($resource -> relations() -> members() as $rel) {
if ($record -> containsRelation($rel)) {
$this -> hydrateRelation($rel, $record);
}
$this -> hydrateRecordRelations($rel -> getResource(), $record);
}
}
@@ -99,7 +113,7 @@ final class AnchorHydrationSet {
$rec = new AnchorRecord($record -> get());
$rid = $record -> relationKeyValue($relation);
$host = $this -> getRecordWithKeyValue($record);
if (!$host -> getRelations() -> includes($relation, $rid)) {
if ($host && !$host -> getRelations() -> includes($relation, $rid)) {
$host -> addRelation($relation, $rec);
}
}
Loading