Dmitry Teplyakov
Dmitry Teplyakov

Reputation: 2908

Query builder and entity inheritance

I have entities:

abstract class AbstractEntity
{
    private $someField;
}

/**
 * ...
 * @ORM\Entity(repositoryClass="ConcreteEntityRepository")
 */
class ConcreteEntity extends AbstractEntity
{
    private $otherField;
}

class ConcreteEntityRepository extends EntityRepository
{
    public function getSomething()
    {
        $qb = $this->getEntityManager()->createQueryBuilder()
            ->select('t')
            ->from('MyBundle:ConcreteEntity', 't');

        $result = $query->getResult();
    }
}

Result will be with correct count of fields but values of parent class will be null. How can I correctly get all the fields?

And when I try to use:

->select('t.someField') // Error

->select('t.otherField') // Good

Upvotes: 0

Views: 1215

Answers (1)

Bram
Bram

Reputation: 1112

My guess is you can't use private properties in your abstract class. Try using protected ones.

The documentation does the same: http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html.

Upvotes: 1

Related Questions