tattersoftware / codeigniter4-schemas

Database schema management, for CodeIgniter 4
MIT License
23 stars 10 forks source link

Access to an undefined property Tatter\Schemas\Structures\Mergeable::$orders. #41

Closed jozefrebjak closed 1 year ago

jozefrebjak commented 1 year ago

I created custom schema

<?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.
jozefrebjak commented 1 year ago

Solved with PHPStan Universal object crates. I added Tatter\Schemas\Structures\Mergeable to the universalObjectCratesClasses: in phpstan.neon.dist config.

MGatner commented 1 year ago

That's the correct approach!