I have a problem with a DQL query and entity specialization.
I have an Entity called Auction
, which is OneToOne
relation with Item
. Item
is a mappedSuperclass
for Film
and Book
. I need a query that could back a search engine, allowing the user to look for auctions with different properties AND
selling items with different properties (it is the AND
part that makes it challenging).
The problem is that even though Auction
has an association pointing to Item
as such, I need to have access to Film
- and Book
-specific fields. The users will specify the Item
type they're looking for, but I don't see any way of using this information other than using INSTANCE OF
in my DQL query.
So far, I have tried using a query like:
SELECT a FROM Entities\Auction a
INNER JOIN a.item i
INNER JOIN i.bookTypes b
WHERE i INSTANCE OF Entities\Book
AND b.type = 'Fantasy'
AND ...".
Such a query results in an error saying that:
Class
Entities\Item
has no field or association namedbookTypes
which is false for Book
, yet true for Item
.
I have also tried
SELECT a FROM Entities\Book i
INNER JOIN i.auction a ...
but I reckon Doctrine requires that I refer to the same Entity in SELECT
and FROM
statements.
If that's of importance, I am using class table inheritance. Still, I don't think switching to single table inheritance would do the trick.
Any ideas?