/
Products.php
41 lines (33 loc) · 1 KB
/
Products.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace CIModuleTests\Support;
use Codenom\Schemas\Structures\Mergeable;
use Codenom\Schemas\Structures\Schema;
use Codenom\Schemas\Structures\Relation;
use Codenom\Schemas\Structures\Table;
use Codenom\Schemas\Structures\Field;
use Codenom\Schemas\Structures\Index;
use Codenom\Schemas\Structures\ForeignKey;
/* SCHEMA */
$schema = new Schema();
/* TABLES */
$schema->tables->products = new Table('products');
$schema->tables->workers = new Table('workers');
/* RELATIONS */
// Products->Workers
$relation = new Relation();
$relation->type = 'belongsTo';
$relation->table = 'workers';
$relation->pivots = [
['products', 'worker_id', 'workers', 'id'],
];
$schema->tables->products->relations->workers = $relation;
// Workers->Products
$relation = new Relation();
$relation->type = 'hasMany';
$relation->table = 'products';
$relation->pivots = [
['workers', 'id', 'products', 'worker_id'],
];
$schema->tables->workers->relations->products = $relation;
/* CLEANUP */
unset($relation);