In relationships table fields user_id and other_user_id are set as indexes type "UNIQUE".
In relationships table fields user_id and other_user_id are should set as indexes type "INDEX".
In below example attached users and user_friends table structure.
Users:
parent: false
properties:
createdAt: { range: "DateTime" }
updatedAt: { range: "DateTime" }
role: { range: "Roles", ormColumn: 'type="bigint"' }
username: { range: "Text", ormColumn: 'type="string", length=255' }
email: { range: "Text", ormColumn: 'type="string", length=255' }
password: { range: "Text", ormColumn: 'type="string", length=255' }
firstName: { range: "Text", ormColumn: 'type="string", length=255, nullable=true' }
lastName: { range: "Text", ormColumn: 'type="string", length=255, nullable=true' }
UserFriends:
parent: false
properties:
createdAt: { range: "DateTime" }
updatedAt: { range: "DateTime" }
User: { range: "Users", ormColumn: 'type="bigint"' }
otherUser: { range: "Users", ormColumn: 'type="bigint"' }
php vendor/bin/schema generate-types src/ app/config/schema.yml
<?php
namespace AppBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* The most generic type of item.
*
* @see http://schema.org/Thing Documentation on Schema.org
*
* @ORM\Entity
* @ApiResource(iri="http://schema.org/Thing")
*/
class Users
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
....
....
....
}
<?php
namespace AppBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* The most generic type of item.
*
* @see http://schema.org/Thing Documentation on Schema.org
*
* @ORM\Entity
* @ApiResource(iri="http://schema.org/Thing")
*/
class UserFriends
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
* @Assert\DateTime
* @Assert\NotNull
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
* @Assert\DateTime
* @Assert\NotNull
*/
private $updatedAt;
/**
* @var Users
*
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Users")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotNull
*/
private $User;
/**
* @var Users
*
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Users")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotNull
*/
private $otherUser;
....
....
....
}
php bin/console doctrine:schema:update --force