Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/RelationMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ private function registerOuterRelation(string $role, string $container, array $r
return;
}

if (isset($relationSchema[Relation::SCHEMA][Relation::INVERSION])) {
// handshaked relation, skip
return;
}

$relation = new ShadowBelongsTo($container, $role, $relationSchema);
$this->dependencies[$relation->getName()] = $relation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ private function makeTables(): void
'order_item_id' => 'int,nullable',
'quantity' => 'int',
]);

$this->makeFK('order_item', 'order_id', 'order', 'id', 'NO ACTION', 'CASCADE');

$this->makeFK('order_item', 'purchase_order_id', 'purchase_order', 'id', 'NO ACTION', 'CASCADE');

$this->makeFK('purchase_order_item', 'purchase_order_id', 'purchase_order', 'id', 'NO ACTION', 'CASCADE');

$this->makeFK('purchase_order_item', 'order_item_id', 'order_item', 'id', 'NO ACTION', 'CASCADE');
}

private function fillData(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
],
Schema::SCOPE => null,
Schema::TYPECAST => [
'id' => 'primary',
'id' => 'int',
'purchase_order_id' => 'int',
'order_item_id' => 'int',
'quantity' => 'int',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489;

use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\Entity\User;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait;
use Cycle\ORM\Tests\Traits\TableTrait;

abstract class CaseTest extends BaseTest
{
use IntegrationTestTrait;
use TableTrait;

public function testSave(): void
{
$this->captureWriteQueries();
$this->save(new User());
$this->assertNumWrites(1);
}

public function setUp(): void
{
// Init DB
parent::setUp();
$this->makeTables();

$this->loadSchema(__DIR__ . '/schema.php');
}

private function makeTables(): void
{
// Make tables
$this->makeTable(User::ROLE, [
'id' => 'primary', // autoincrement
'user_id' => 'int,nullable',
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\Entity;

class User
{
public const ROLE = 'user';

public ?int $id = null;
public ?int $user_id = null;
public ?self $user = null;
public iterable $users = [];
}
65 changes: 65 additions & 0 deletions tests/ORM/Functional/Driver/Common/Integration/Issue489/schema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\Relation;
use Cycle\ORM\Schema\GeneratedField;
use Cycle\ORM\SchemaInterface as Schema;
use Cycle\ORM\Select\Repository;
use Cycle\ORM\Select\Source;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\Entity\User;

return [
'user' => [
Schema::ENTITY => User::class,
Schema::SOURCE => Source::class,
Schema::MAPPER => Mapper::class,
Schema::REPOSITORY => Repository::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user',
Schema::PRIMARY_KEY => ['id'],
Schema::FIND_BY_KEYS => ['id'],
Schema::COLUMNS => [
'id' => 'id',
'user_id' => 'user_id',
],
Schema::RELATIONS => [
'user' => [
Relation::TYPE => Relation::BELONGS_TO,
Relation::TARGET => 'user',
Relation::LOAD => Relation::LOAD_PROMISE,
Relation::SCHEMA => [
Relation::CASCADE => true,
Relation::NULLABLE => true,
Relation::INNER_KEY => 'user_id',
Relation::OUTER_KEY => ['id'],
// Relation::INVERSION => 'users',
],
],
'users' => [
Relation::TYPE => Relation::HAS_MANY,
Relation::TARGET => 'user',
Relation::LOAD => Relation::LOAD_PROMISE,
Relation::SCHEMA => [
Relation::CASCADE => true,
Relation::NULLABLE => false, // The reason for the issue
Relation::WHERE => [],
Relation::ORDER_BY => [],
Relation::INNER_KEY => ['id'],
Relation::OUTER_KEY => 'user_id',
// Relation::INVERSION => 'user',
],
],
],
Schema::SCOPE => null,
Schema::TYPECAST => [
'id' => 'int',
'user_id' => 'int',
],
Schema::SCHEMA => [],
Schema::GENERATED_FIELDS => [
'id' => GeneratedField::ON_INSERT,
],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\MySQL\Integration\Issue489;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\CaseTest as CommonClass;

/**
* @group driver
* @group driver-mysql
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'mysql';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Postgres\Integration\Issue489;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\CaseTest as CommonClass;

/**
* @group driver
* @group driver-postgres
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'postgres';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\SQLServer\Integration\Issue489;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlserver
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlserver';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\SQLite\Integration\Issue489;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue489\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlite';
}
Loading