i’m working on a symfony project, with propel ORM. In my model, i have a table where its elements can be linked with many elements of the same table, by another table (link table). Some code will explain better:
table1:
id_element: integer;
[...]
and the link table:
link_table:
id1: fk to table1;
id2: fk to table1;
i need to build a query with Propel Criteria that returns me all the related elements with an specific element. The problem is that the element i want to specify, can be as in id1 field as in id2 field of the link table.
now some of my criteria definition code (not working obviously)
$c = new Criteria();
$c->addJoin($linkTable::ID1,$table::ID);
$c->addJoin($linkTable::ID2,$table::ID);
$c->addOr($linkTable::ID1,$specific_id);
$c->addOr($linkTable::ID2,$specific_id);
$result = $table->doSelect($c);
and this is a SQL like that I want to generate:
SELECT * FROM table
WHERE table.ID IN
(SELECT link_table.ID1 FROM link_table
WHERE link_table.ID2 = "the id that i want"
)
OR table.ID IN
(SELECT link_table.ID2 FROM link_table
WHERE link_table.ID1 = "the id that i want"
)
So must i do 2 joins, one for each side of the link table? is there a way to do an “or-join“? Please help me!
Thank you very much for your time 🙂
at last i found a way to do it using criteria:
maybe not the best way but working fine.
Thank you very much for your answers!!