Reputation: 868
fellow programmers :)
I'm having a bad case of no idea what's going on.
This concerns two entities: Ware
and File
.
In my repository, I have a function that returns File
objects along with wares to avoid lazy loading:
The relevant part of this function ( because the exception happens even if i trigger this bit only ) is this:
public function findByWithFilesTotal($params, $page = false, $per_page = false){
$res = $this->_em->createQuery('SELECT w, f FROM ShopBundle:Ware w JOIN w.files f');
// same result occurs with LEFT JOIN
return count($res->getResult());
}
Important stuff: 1) Ware and File classes are direct descendants of class Data. Discriminators are all right.
2) Ware has OneToMany relation with File - that means File table has ware_id column.
3) This is the most important part ( IMHO ). I use this filter to separate deleted items in all Data
descendants.
class UndeletedFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
if(!$targetEntity->hasField('deleted'))
return "";
return "( $targetTableAlias.deleted = 0 OR $targetTableAlias.deleted IS NULL)";
}
}
It works for all the other entities, but causes a HydrationException with message 'The discriminator column "discr" is missing for "Acme\CoreBundle\Entity\File" using the DQL alias "f".' for this one query.
This, however, DOES NOT happen if I either remove JOIN w.files
from DQL query, and leave it to lazy loading, or return an empty string from addFilterConstraint()
method even if it does have the 'deleted' field.
So, if anyone knows: What exactly causes this, and how do solve it?
Thank you in advance :)
Upvotes: 0
Views: 3200
Reputation: 14747
One reason for trigger this exception in when you are working inherent classes, then for example, if your discriminator column
has null
values the QueryBuilder will do not know how to convert this unknown type based in type.
Upvotes: 3