<?php
declare(strict_types=1);
namespace Modules\Schemas\Custom;
use Tatter\Schemas\Structures\Relation;
use Tatter\Schemas\Structures\Schema;
use Tatter\Schemas\Structures\Table;
// SCHEMA
$schema = new Schema();
// TABLES
$schema->tables->orders = new Table('orders');
$schema->tables->users = new Table('users');
// RELATIONS
// Orders->Users
$relation = new Relation();
$relation->type = 'belongsTo';
$relation->table = 'users';
$relation->pivots = [
['orders', 'disponent_id', 'users', 'id'],
];
$schema->tables->orders->relations->users = $relation;
// Users->Orders
$relation = new Relation();
$relation->type = 'hasMany';
$relation->table = 'orders';
$relation->pivots = [
['users', 'id', 'orders', 'disponent_id'],
];
$schema->tables->users->relations->orders = $relation;
// CLEANUP
unset($relation);
it's working as expected, but thre is an Phpstan issue.
Line modules/Schemas/Custom/Orders.php
------ -------------------------------------------------------------------------------
15 Access to an undefined property Tatter\Schemas\Structures\Mergeable::$orders.
16 Access to an undefined property Tatter\Schemas\Structures\Mergeable::$users.
26 Access to an undefined property Tatter\Schemas\Structures\Mergeable::$users.
35 Access to an undefined property Tatter\Schemas\Structures\Mergeable::$orders.
Solved with PHPStan Universal object crates. I added Tatter\Schemas\Structures\Mergeable to the universalObjectCratesClasses: in phpstan.neon.dist config.
I created custom schema
it's working as expected, but thre is an Phpstan issue.