So here's one way to just replicate what you have in the SQL, but as I mention in my comment, there may be a more efficient way to do it. If you provide an answer to my comment question above I'll see if I can improve this answer.
First, you will need a cross reference table in your schema. I'll assume that you do, and that it is called AttributeValue
. Then you add your joins to the EntityQuery
and add additional conditions.
Unfortunately, it looks like there may be a bug in Propel that will prevent the code below from producing the proper SQL.
$results = EntityQuery::create()
->join('Entity.AttributeValue avx')
->join('avx.Attribute xa')
->addJoinCondition('xa', 'xa.name = ?', 'X')
->join('Entity.AttributeValue avy')
->join('avy.Attribute ya')
->addJoinCondition('ya', 'ya.name = ?', 'Y')
->select(array('entity.name', 'avx.value', 'avy.value'));
This should produce the following SQL:
SELECT entity.name AS 'entity.name',
avx.value AS 'avx.value',
avy.value AS 'avy.value'
FROM `entity`
INNER JOIN `attribute_value` `avx` ON (entity.id = avx.entity_id)
INNER JOIN `attribute` `ax` ON (avx.attribute_id = ax.id AND ax.name = 'X')
INNER JOIN `attribute_value` `avy` ON (entity.id = avy.entity_id)
INNER JOIN `attribute` `ay` ON (avy.attribute_id = ay.id AND ay.name = 'Y')
Unfortunately, this is produced instead:
SELECT entity.name AS 'entity.name',
aatribute_value.value AS 'avx.value',
aatribute_value.value AS 'avx.value'
FROM `entity`
INNER JOIN `attribute_value` `avx` ON (entity.id = avx.entity_id)
INNER JOIN `attribute` `ax` ON (avx.attribute_id = ax.id AND attribute.name = 'X')
INNER JOIN `attribute_value` `avy` ON (entity.id = avy.entity_id)
INNER JOIN `attribute` `ay` ON (avy.attribute_id = ay.id AND attribute.name = 'Y')
(The problem is the SELECT
line and the INNER JOIN
on attribute
which uses attribute.name = 'X'
instead of the proper ax.name = 'X'
.)
So, you could run the correct SQL using a manual query, or wait for the bug to be fixed (I'll try to write up an issue on guthub and work on a fix.)
Sorry I couldn't be of more help.
Information gathered from the Propel documentation on joining tables.