Skip to content

Commit 7669fd9

Browse files
committed
Adding badges
1 parent dbaef00 commit 7669fd9

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![Latest Stable Version](https://poser.pugx.org/mouf/schema-analyzer/v/stable)](https://packagist.org/packages/mouf/schema-analyzer)
2+
[![Latest Unstable Version](https://poser.pugx.org/mouf/schema-analyzer/v/unstable)](https://packagist.org/packages/mouf/schema-analyzer)
3+
[![License](https://poser.pugx.org/mouf/schema-analyzer/license)](https://packagist.org/packages/mouf/schema-analyzer)
14
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/schema-analyzer/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/schema-analyzer/?branch=1.0)
25
[![Build Status](https://travis-ci.org/thecodingmachine/schema-analyzer.svg?branch=1.0)](https://travis-ci.org/thecodingmachine/schema-analyzer)
36
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/schema-analyzer/badge.svg?branch=1.0&service=github)](https://coveralls.io/github/thecodingmachine/schema-analyzer?branch=1.0)
@@ -26,6 +29,41 @@ You can install this package through Composer:
2629
The packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility
2730
between minor versions.
2831

29-
## Usage
32+
## Detecting junction tables
3033

31-
Start by instanciating
34+
The starting point is always a DBAL Schema. Pass the schema to SchemaAnalyzer, and then, simply call the functions.
35+
36+
```php
37+
// $conn is the DBAL connection.
38+
$schema = $conn->getSchemaManager()->createSchema();
39+
40+
// Let's detect all junctions tables
41+
$tables = $schema->detectJunctionTables();
42+
// This will return an array of Doctrine\DBAL\Schema\Table objects
43+
```
44+
45+
A **junction table** is a table:
46+
47+
- that has **exactly 2 foreign keys**
48+
- that has **only 2 columns** (or **3 columns** if the one of those is an *autoincremented primary key*).
49+
50+
## Computing the shortest path between 2 tables
51+
52+
Following foreign keys, the `getShortestPath` function will try to find the shortest path between 2 tables.
53+
It will return the list of foreign keys it used to link the 2 tables.
54+
55+
Internals:
56+
57+
- Each foreign key has a *cost* of 1
58+
- Junction tables have a cost of 1.5, instead of 2 (one for each foreign key)
59+
60+
```php
61+
// $conn is the DBAL connection.
62+
$schema = $conn->getSchemaManager()->createSchema();
63+
64+
// Let's detect the shortest path between 2 tables:
65+
$fks = $schema->getShortestPath("users", "rights");
66+
// This will return an array of Doctrine\DBAL\Schema\ForeignKeyConstraint objects
67+
```
68+
69+
// TODO: Ambiguity exception!

0 commit comments

Comments
 (0)