public function toArrayWithImmediateRelationships(RelationalTableGateway $TableGateway) { if ($this->table !== $TableGateway->getTable()) { throw new \InvalidArgumentException('The table of the gateway parameter must match this row\'s table.'); } $entry = $this->toArray(); $schemaArray = TableSchema::getSchemaArray($this->table); $aliasColumns = $TableGateway->filterSchemaAliasFields($schemaArray); // Many-to-One list($entry) = $TableGateway->loadManyToOneRelationships($schemaArray, [$entry]); // One-to-Many, Many-to-Many $entry = $TableGateway->loadToManyRelationships($entry, $aliasColumns); return $entry; }