Skip to content

Loading…

DDC-1250: Ambiguous column in query using one-to-one self-referencing bidirectional association #1860

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user saniok:

This example worked fine with 2.0.6. I suppose it is related to:
"Furthermore inverse OneToOne associations previously always executed an additional query, which is now replaced with a join."

When I try to get object using EntityRepository I receive following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'declinedclients_historyid' in where clause is ambiguous' in /usr/share/php/Doctrine/DBAL/Connection.php:613
Stack trace:
#0 /usr/share/php/Doctrine/DBAL/Connection.php(613): PDOStatement->execute()
#1 /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php(569): Doctrine\DBAL\Connection->executeQuery('SELECT t0.id AS...', Array, Array)
#2 /usr/share/php/Doctrine/ORM/Persisters/BasicEntityPersister.php(644): Doctrine\ORM\Persisters\BasicEntityPersister->load(Array, NULL, Array)
#3 /usr/share/php/Doctrine/ORM/UnitOfWork.php(2015): Doctrine\ORM\Persisters\BasicEntityPersister->loadOneToOneEntity(Array, Object(Entities\ClientsHistory), NULL)
#4 /usr/share/php/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php(208): Doctrine\ORM\UnitOfWork->createEntity('Entities\Client...', Array, Array)
#5 /usr/share/php/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php(398): Doctrine\ORM\Internal\Hydration\Ob in /usr/share/php/Doctrine/DBAL/Connection.php on line 613

Entity YAML:

Entities\ClientsHistory:
type: entity
table: clients_history
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
[...skiped...]
oneToOne:
declinedClientsHistory:
targetEntity: Entities\ClientsHistory
joinColumn:
name: declinedclients_historyid
referencedColumnName: id
inversedBy: declinedBy
declinedBy:
targetEntity: Entities\ClientsHistory
mappedBy: declinedClientsHistory
lifecycleCallbacks: { }
repositoryClass: Entities\ClientsHistoryRepository

Query which lead to error:
SELECT t0.id AS id1, t0.odate AS odate2, t0.oper AS oper3, t0.type AS type4, t0.transactionsum AS transaction_sum5, t0.sum AS sum6, t0.balance AS balance7, t0.descr AS descr8, t0.admin AS admin9, t0.payment_id AS payment_id10, t0.balance_operation_id AS balance_operation_id11, t0.payment_id AS payment_id12, t0.declined_clients_history_id AS declined_clients_history_id13, t14.id AS id15, t14.odate AS odate16, t14.oper AS oper17, t14.type AS type18, t14.transaction_sum AS transaction_sum19, t14.sum AS sum20, t14.balance AS balance21, t14.descr AS descr22, t14.admin AS admin23, t14.payment_id AS payment_id24, t14.balance_operation_id AS balance_operation_id25, t14.payment_id AS payment_id26, t14.declined_clients_history_id AS declined_clients_history_id27, t14.id_clients AS id_clients28, t14.id_domains AS id_domains29, t0.id_clients AS id_clients30, t0.id_domains AS id_domains31 FROM clients_history t0 LEFT JOIN clients_history t14 ON t14.declined_clients_history_id = t0.id WHERE declined_clients_historyid = ?

@doctrinebot

Comment created by @beberlei:

What kind of operation are you using that leads to this error? $em->find ( parent) or something more complex?

@doctrinebot

Comment created by @beberlei:

I could reproduce it, it happens when you do a DQL without fetching the related One To One.

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.