Skip to content

Commit 7653d3b

Browse files
committed
Adding some documentation
1 parent 5643f55 commit 7653d3b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,20 @@ $posts = $db->table('posts')->column('title')->string(50)->graphqlField() // The
5858
->failWith(null) // If the user is not logged or has no right, let's serve 'null'
5959
->endGraphql();
6060

61+
// You can pass instructions on how JSON serialization occurs.
62+
// This will generate a set of JSONxxx annotations.
63+
$nodes = $db->table('nodes')
64+
->column('id')->integer()->primaryKey()->autoIncrement()->jsonSerialize()->ignore()
65+
->column('alias_id')->references('nodes')->null()->jsonSerialize()->recursive()
66+
->column('parent_id')->references('nodes')->null()->jsonSerialize()->include()
67+
->column('root_id')->references('nodes')->null()->jsonSerialize()->ignore()
68+
->column('owner_id')->references('authors')->null()->jsonSerialize()->formatUsingProperty('name')->include()
69+
->column('owner_country')->references('authors')->null()->jsonSerialize()->formatUsingMethod('getCountryName')->include()
70+
->column('name')->string()->jsonSerialize()->key('basename')
71+
->column('size')->integer()->notNull()->default(0)->jsonSerialize()->numericFormat(null, null, null, ' o')
72+
->column('weight')->float()->null()->jsonSerialize()->numericFormat(2, ',', '.', 'g')
73+
->column('created_at')->date()->null()->jsonSerialize()->datetimeFormat("Y-m-d")
74+
->column('another_parent')->references('nodes')->comment('@JsonCollection("entries") @JsonFormat(property="entry")');
75+
6176
$db->junctionTable('posts', 'users')->graphqlField(); // Expose the many-to-many relationship as a GraphQL field.
6277
```

tests/TdbmFluidJunctionTableJsonOptionsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function testJson()
1919
->column('parent_id')->references('nodes')->null()->jsonSerialize()->include()
2020
->column('root_id')->references('nodes')->null()->jsonSerialize()->ignore()
2121
->column('owner_id')->references('nodes')->null()->jsonSerialize()->formatUsingProperty('name')->include()
22+
->column('owner_country')->references('nodes')->null()->jsonSerialize()->formatUsingMethod('myMethod')->include()
2223
->column('name')->string()->jsonSerialize()->key('basename')
2324
->column('size')->integer()->notNull()->default(0)->jsonSerialize()->numericFormat(null, null, null, ' o')
2425
->column('weight')->float()->null()->jsonSerialize()->numericFormat(2, ',', '.', 'g')
@@ -31,10 +32,14 @@ public function testJson()
3132
$this->assertContains("@JsonInclude", $nodesTable->getColumn('parent_id')->getComment());
3233
$this->assertContains("@JsonIgnore", $nodesTable->getColumn('root_id')->getComment());
3334
$this->assertContains('@JsonFormat(property = "name")', $nodesTable->getColumn('owner_id')->getComment());
35+
$this->assertContains('@JsonFormat(method = "myMethod")', $nodesTable->getColumn('owner_country')->getComment());
3436
$this->assertContains("@JsonKey(key = \"basename\")", $nodesTable->getColumn('name')->getComment());
3537
$this->assertContains("@JsonFormat(unit = \" o\")", $nodesTable->getColumn('size')->getComment());
3638
$this->assertContains("@JsonFormat(decimals = 2, point = \",\", separator = \".\", unit = \"g\")", $nodesTable->getColumn('weight')->getComment());
3739
$this->assertContains("@JsonFormat(date = \"Y-m-d\")", $nodesTable->getColumn('created_at')->getComment());
3840
$this->assertContains("@JsonCollection(\"entries\")", $nodesTable->getColumn('another_parent')->getComment());
41+
42+
$anotherColumn = $fluid->table('nodes')->column('another_column')->integer();
43+
$this->assertSame($anotherColumn, $anotherColumn->jsonSerialize()->endJsonSerialize());
3944
}
4045
}

0 commit comments

Comments
 (0)