Doctrine2 One-To-Many / Many-To-One relations

后端 未结 2 621
傲寒
傲寒 2021-02-03 13:51

So, 1:M / M:1 relations don\'t work the way M:M relations work (obviously), but I thought that with proper configuration, you can get the same output as a M:M relation.

2条回答
  •  囚心锁ツ
    2021-02-03 14:22

    Looks like you're doing it right. Don't worry about the PersistentCollection/ArrayCollection stuff -- all that matters is that they're collections.

    $Path->getOffers() should indeed return a collection of PathOffers, and each PathOffer should have an offer.

    So it ought to work like this:

    //Output a all offers associated with a path, along with the position.
    $pathOffers = $path->getOffers();
    
    foreach($pathOffers as $po){
        echo $po->getOffer()->id . ' [' . $po->getPosition() . "]\n";
    } 
    

    Am I missing something?

提交回复
热议问题