1 | <?php |
||
28 | class BelongsToSchema extends AbstractSchema |
||
29 | { |
||
30 | use TablesTrait, TypecastTrait, ForeignsTrait; |
||
31 | |||
32 | /** |
||
33 | * Relation type. |
||
34 | */ |
||
35 | const RELATION_TYPE = Record::BELONGS_TO; |
||
36 | |||
37 | /** |
||
38 | * Options needed in runtime. |
||
39 | */ |
||
40 | const PACK_OPTIONS = [Record::INNER_KEY, Record::OUTER_KEY, Record::NULLABLE]; |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | const OPTIONS_TEMPLATE = [ |
||
46 | //Outer key is primary key of related record by default |
||
47 | Record::OUTER_KEY => '{target:primaryKey}', |
||
48 | |||
49 | //Inner key will be based on singular name of relation and outer key name |
||
50 | Record::INNER_KEY => '{relation:singular}_{option:outerKey}', |
||
51 | |||
52 | //Set constraints (foreign keys) by default |
||
53 | Record::CREATE_CONSTRAINT => true, |
||
54 | |||
55 | //@link https://en.wikipedia.org/wiki/Foreign_key |
||
56 | Record::CONSTRAINT_ACTION => 'CASCADE', |
||
57 | |||
58 | //Relation allowed to create indexes in inner table |
||
59 | Record::CREATE_INDEXES => true, |
||
60 | |||
61 | //We are going to make all relations nullable by default, so we can add fields to existed |
||
62 | //tables without raising an exceptions |
||
63 | Record::NULLABLE => true, |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function declareTables(SchemaBuilder $builder): array |
||
111 | } |