Doctrine 2.5 可嵌入:"Unknown Column"
Doctrine 2.5 Embeddable: "Unknown Column"
我有一个用户 class 看起来像这样:
/**
* @Entity @Table(name="users")
**/
class User {
/**
* @Id @Column(type="string")
**/
protected $id;
/**
* @var Password user's password
* @Embedded(class="Acme\Users\Password")
*/
private $password;
/**
* @var Email user's email address
* @Embedded(class="Acme\Users\Email")
*/
private $email;
/* .... More .... */
}
还有一个密码 class,如下所示:
/**
* @Embeddable
*/
class Password {
/**
* @Column(type="string")
*/
private $password = NULL;
}
当我试图用这个找到用户时:
$this->repository->findOneBy([
"email.email" => $email->toString()
]);
我收到这样的错误:
Next exception 'Doctrine\DBAL\Exception\InvalidFieldNameException' with message 'An exception occurred while executing 'SELECT t0.id AS id_1, t0.password AS password_2, t0.email_email AS email_email_3 FROM users t0 WHERE t0.email_email = ? LIMIT 1' with params ["jason@email.com"]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.password' in 'field list'' in /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:71
Stack trace:
#0 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(116): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(836): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT t0.id AS...', Array)
#2 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(715): Doctrine\DBAL\Connection->executeQuery('SELECT t0.id AS...', Array, Array)
#3 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php(196): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(Array, NULL, NULL, Array, NULL, 1, NULL)
#4 /Users/jason/Workspace/Personal/acme-bdd/app/Acme/Users/DoctrineUserRepository.php(42): Doctrine\ORM\EntityRepository->findOneBy(Array)
#5 /Users/jason/Workspace/Personal/acme-bdd/app/Acme/Users/Commands/AttemptSignInCommandHandler.php(15): Acme\Users\DoctrineUserRepository->findByEmail(Object(Acme\Users\Email))
#6 /Users/jason/Workspace/Personal/acme-bdd/vendor/league/tactician/src/HandlerCommandBus.php(55): Acme\Users\Commands\AttemptSignInCommandHandler->handleAttemptSignInCommand(Object(Acme\Users\Commands\AttemptSignInCommand))
我安装了这些软件包:
$ composer show -i | grep doctrine
doctrine/annotations dev-master b5202eb Docblock Annotations Parser
doctrine/cache dev-master dbeacc7 Caching library offering an object-oriented API for many cache backends
doctrine/collections dev-master c63f2e6 Collections Abstraction library
doctrine/common dev-master 56360cc Common Library for Doctrine projects
doctrine/dbal 2.5.x-dev 67c4701 Database Abstraction Layer
doctrine/inflector dev-master e5eaf8c Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator dev-master 3d9669e A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer dev-master 83893c5 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations dev-master 1ac14fa Database Schema migrations using Doctrine DBAL
doctrine/orm dev-master 4a05e19 Object-Relational-Mapper for PHP
据我所知,我做的一切都是对的。对可能出现的问题有帮助吗?
问题原来是 PHP 的版本不兼容。我升级到最新版本,问题消失了。
我有一个用户 class 看起来像这样:
/**
* @Entity @Table(name="users")
**/
class User {
/**
* @Id @Column(type="string")
**/
protected $id;
/**
* @var Password user's password
* @Embedded(class="Acme\Users\Password")
*/
private $password;
/**
* @var Email user's email address
* @Embedded(class="Acme\Users\Email")
*/
private $email;
/* .... More .... */
}
还有一个密码 class,如下所示:
/**
* @Embeddable
*/
class Password {
/**
* @Column(type="string")
*/
private $password = NULL;
}
当我试图用这个找到用户时:
$this->repository->findOneBy([
"email.email" => $email->toString()
]);
我收到这样的错误:
Next exception 'Doctrine\DBAL\Exception\InvalidFieldNameException' with message 'An exception occurred while executing 'SELECT t0.id AS id_1, t0.password AS password_2, t0.email_email AS email_email_3 FROM users t0 WHERE t0.email_email = ? LIMIT 1' with params ["jason@email.com"]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.password' in 'field list'' in /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:71
Stack trace:
#0 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(116): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(836): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT t0.id AS...', Array)
#2 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(715): Doctrine\DBAL\Connection->executeQuery('SELECT t0.id AS...', Array, Array)
#3 /Users/jason/Workspace/Personal/acme-bdd/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php(196): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(Array, NULL, NULL, Array, NULL, 1, NULL)
#4 /Users/jason/Workspace/Personal/acme-bdd/app/Acme/Users/DoctrineUserRepository.php(42): Doctrine\ORM\EntityRepository->findOneBy(Array)
#5 /Users/jason/Workspace/Personal/acme-bdd/app/Acme/Users/Commands/AttemptSignInCommandHandler.php(15): Acme\Users\DoctrineUserRepository->findByEmail(Object(Acme\Users\Email))
#6 /Users/jason/Workspace/Personal/acme-bdd/vendor/league/tactician/src/HandlerCommandBus.php(55): Acme\Users\Commands\AttemptSignInCommandHandler->handleAttemptSignInCommand(Object(Acme\Users\Commands\AttemptSignInCommand))
我安装了这些软件包:
$ composer show -i | grep doctrine
doctrine/annotations dev-master b5202eb Docblock Annotations Parser
doctrine/cache dev-master dbeacc7 Caching library offering an object-oriented API for many cache backends
doctrine/collections dev-master c63f2e6 Collections Abstraction library
doctrine/common dev-master 56360cc Common Library for Doctrine projects
doctrine/dbal 2.5.x-dev 67c4701 Database Abstraction Layer
doctrine/inflector dev-master e5eaf8c Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator dev-master 3d9669e A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer dev-master 83893c5 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations dev-master 1ac14fa Database Schema migrations using Doctrine DBAL
doctrine/orm dev-master 4a05e19 Object-Relational-Mapper for PHP
据我所知,我做的一切都是对的。对可能出现的问题有帮助吗?
问题原来是 PHP 的版本不兼容。我升级到最新版本,问题消失了。