1
目前我使用Doctrine2的價值對象,它的工作很好。當我用值對象只有一個字段,例如問題:只有一個字段的學說價值對象
$this->repository->findBy(array('email' => '[email protected]')); //This is not working
$this->repository->findBy(array('email.email' => '[email protected]')); //This is work great
的問題是,如何讓$這個 - > repository-> findBy(陣列(「郵件」 =>「名@域名。 COM'));加工?
這是我的教訓映射
User.orm.xml
<!-- User.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
<entity name="Domain\User\Entity\User" table="users" repository-class="Infrastructure\User\Repository\UserRepository">
<id name="id" type="guid">
<generator strategy="UUID"/>
</id>
<embedded name="email" class="Shared\ValueObject\Email" use-column-prefix="false" />
</entity>
</doctrine-mapping>
Email.orm.xml
<!-- Email.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="Shared\ValueObject\Email">
<field name="email" type="string" length="80" />
</embeddable>
</doctrine-mapping>
謝謝您的幫助,對不起我的英文不好。