Skip to content

Commit 5a3f6d8

Browse files
authored
Merge pull request #8 from moufmouf/output_id_ref
Fixing an issue with output="ID" set on foreign keys
2 parents ebbc3dc + 9173368 commit 5a3f6d8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/TdbmFluidColumnGraphqlOptions.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ private function generateFieldAnnotation(): void
6363
if ($this->outputType !== null) {
6464
$outputType = $this->outputType;
6565
} elseif ($this->fluidColumn->getDbalColumn()->getType() === Type::getType(Type::GUID)) {
66-
$outputType = 'ID';
66+
// are we part of a foreign key or not?
67+
$fks = $this->tdbmFluidColumnOptions->then()->getDbalTable()->getForeignKeys();
68+
$isPartOfFk = false;
69+
foreach ($fks as $fk) {
70+
if (in_array($this->fluidColumn->getDbalColumn()->getName(), $fk->getLocalColumns(), true) === true) {
71+
$isPartOfFk = true;
72+
break;
73+
}
74+
}
75+
if ($isPartOfFk === false) {
76+
$outputType = 'ID';
77+
}
6778
} else {
6879
// If the column is the primary key, let's add an ID type
6980
$pk = $this->tdbmFluidColumnOptions->then()->getDbalTable()->getPrimaryKey();

tests/TdbmFluidColumnGraphqlOptionsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ public function testGraphql()
5252
$uuidColumn = $users->uuid()->graphqlField();
5353
$this->assertContains('outputType = "ID"', $schema->getTable('users')->getColumn('uuid')->getComment());
5454

55+
$products = $fluid->table('products')
56+
->uuid()
57+
->column('user_id')->references('users')->graphqlField();
58+
$this->assertNotContains('outputType = "ID"', $schema->getTable('products')->getColumn('user_id')->getComment());
5559
}
5660
}

0 commit comments

Comments
 (0)