1
votes

We are using Propel (1.7) for PHP. And I have some problems with hydrating joined objects.

Here is an example:

Table A
-------- 
id
anyColumn

Table B
-------- 
id
a_id

With propel I'm querying for objects from Table A, but want to (left) join the entries from b.

The query looks like:

$as = AQuery::create()->filterByAnyColumn(anyValue)->leftJoinWithB()->find();

I outputted the mysql query and it looks good. I also called the query manually and all columns from b where there too. So everything looks good so far... BUT:

If I'm having an object from a now and call $a->getBs(); propel will create a new query. But I thought that I could avoid this query because I already joined B. What am I doing wrong?

1

1 Answers

0
votes

Please try using joinWith():

$as = AQuery::create()
    ->filterByAnyColumn(anyValue)
    ->joinWith('A.B')
    ->find();

Details can be found here: propelorm.org/Propel/reference/model-criteria.html#minimizing-queries