tags:

views:

32

answers:

1

I have 3 table: ["Order", "Order_to_goods", "Goods"]

I want to get of all participants of many-to-many relationships, by Order_ID, to can do something like that:

$Order = Doctrine::getTable('Order')->findOneById( 1 );
$Order ->loadReleated('Goods');

foreach( $Order->Goods as $product){...}

But it isn't work. Having tried everything I despair. Can you give me some helpfull council.

Addition

To get a nested values need a few operations:

    $this->orderObject->loadReference('StoreOrderToItem');
    foreach($this->orderObject->StoreOrderToItem as $OrderToItem)
    {
        $OrderToItem->loadReference('StoreItem');
    }

And few queries to DB, to get complete object:

SELECT s.order_id AS s__order_id, s.goods_id AS s__goods_id, s.count AS s__count, s.price AS s__price FROM store_order_to_item s WHERE (s.order_id IN (?))

SELECT s.id AS s__id, s.section_id AS s__section_id, s.payment_strategy_id AS s__payment_strategy_id, s.name AS s__name, s.title AS s__title, s.description AS s__description, s.price AS s__price, s.creation_date AS s__creation_date, s.status AS s__status, s.sort AS s__sort FROM store_item s WHERE (s.id = ?)

SELECT s.id AS s__id, s.section_id AS s__section_id, s.payment_strategy_id AS s__payment_strategy_id, s.name AS s__name, s.title AS s__title, s.description AS s__description, s.price AS s__price, s.creation_date AS s__creation_date, s.status AS s__status, s.sort AS s__sort FROM store_item s WHERE (s.id = ?)

What if there is not only one or two rows in DB, there is thousands rows. There is a necessity to combine all in one query (with LEFT JOIN operands). How can do this, If all relations are put right? Doctrine Documentation failed to disclose this problem for me. I hope you could help me.

PS: Sorry for my English, I write this above 30 minutes =))

A: 

I found th solution:

    $q = $this->createQuery('dctrn_findProduct')
            ->from('JV_Model_StoreOrder o')
            ->leftJoin('o.StoreOrderToItem oi WITH oi.order_id = o.id')
            ->leftJoin('oi.StoreItem i WITH i.id = oi.goods_id')
            ->addWhere('o.id = ?', $order_id);

    $r = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

He does not act as mysql, using is not simple SQL queries.

HWTech