Search code examples
phpmysqlormpropelentity-attribute-value

Working with EAV model in Propel


I have a database with a EAV structure, having this tables :

Entity (id, name)
Attribute (id, name)
AttributeValue(fk_id_entity, fk_id_attribute, value)

What I want to do is translate this following query in Propel:

SELECT entity.name, avx.value, avy.value
FROM Entity entity
INNER JOIN AttributeValue avx ON (avx.fk_id_entity = entity.id 
AND avx.name = 'X')
INNER JOIN AttributeValue avy ON (avy.fk_id_entity = entity.id 
AND avy.name = 'Y')

Any idea how could I do this in Popel? Thank you!

LE: The ideea is that each entity has two attributes X and Y, and I would like to display a list of all entities along with their X and Y attributes.


Solution

  • What it actually worked is the following:

    $result = Entity_EntityQuery::create()
    ->withColumn('alias1.value', 'xvalue')
    ->withColumn('alias2.value', 'yvalue')
    ->innerjoinValue('alias1')
    ->useValueQuery('alias1')
    ->filterbyFkAttribute('x attribute id')
    ->endUse()
    ->innerjoinValue('alias1')
    ->useValueQuery('alias1')
    ->filterbyFkAttribute('y attribute id')
    ->endUse()
    ...//conditions
    ->find()
    

    Thanks everybody for viewing and replying!