Doctrine - Unilateral bi-directional relationship not allowed

I had a problem migrating my database design to Doctrine.

First, some details:

I get a lot of soccer related data from xml files and have to save it in my own database.

One of these data is the statistics of players and players.

Here are my tables:

table: player id | varchar | PK team_id | int ...and many more... table: player_statistic player_id | varchar | PK season_id | smallint | PK competition_id | smallint | PK ...and many more... 

Thus, player.id is part of the composite PC of player_statistic.

In my opinion, this is a one-to-one relationship.

Here is the corresponding entity code:

 <?php /** * @Entity * @Table(name="player") */ class Player { /** * @Id * @OneToOne(targetEntity="PlayerStatistic", mappedBy="playerId") */ private $id; /* ... */ } ?> <?php /** * @Entity * @Table(name="player_statistic") */ class PlayerStatistic { /** * @Id * @OneToOne(targetEntity="Player", inversedBy="id") * @JoinColumn(name="player_id", referencedColumnName="id") */ private $playerId; /* ... */ } ?> 

CLI Command:

 php53 vendor/bin/doctrine orm:schema-tool:update --dump-sql 

returns: "Inverse association cannot be an identifier in" Player # id ".

As a rule, is it impossible to do this or is something wrong?

If it’s possible and not complete garbage, I do not want to use additional AI PK fields.

Thanks for any help.

UPDATE Sorry that the logical problem is related to the relation (player_statistic) to one (player).

+4
source share

Source: https://habr.com/ru/post/1480919/


All Articles