laravel-doctrine / fluent

Fluent mapping driver for Doctrine2

Home Page:http://www.laraveldoctrine.org/docs/current/fluent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

findOneBy() and findBy() not working with embedded fields

catalinbuletin opened this issue · comments

This is part of my UserMapping

public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->embed(FirstName::class)->noPrefix();
        $builder->embed(LastName::class)->noPrefix();
        $builder->embed(Email::class)->noPrefix();
    }

When I try to:

        $users = $this->userRepository->findOneBy([
            'email' => 'email@example.com'
        ]);

I get this:
Doctrine \ ORM \ ORMException Unrecognized field: email

But if I change the UserMapping to use a string instead of the embedded field

public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->embed(FirstName::class)->noPrefix();
        $builder->embed(LastName::class)->noPrefix();
        $builder->string('email');
    }

This will work as expected.

Any thoughts of why i get Unrecognized field: email when the field is a ValueObject?

Thank you!

This is not really a specific Fluent problem. This is how Doctrine embedded fields work.

You need to query on the embedded name and the field within that embedded.
E.g.:

 $users = $this->userRepository->findOneBy([
            'email.address' => 'email@example.com'
        ]);

See for example: https://stackoverflow.com/questions/30321224/doctrine-orm-querying-by-value-object-throws-a-semantic-error-mappings-for-inse

You are right! Thanks for your input and for the package as well! Keep it up!