title: Doctrine2 One-To-Many / Many-To-One relations
body: <p>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.</p>
  
  <p>Basically, I needed to add another field (position), to <code>path_offer</code>.</p>
  
  <p>I thought I got it to work until I tried to use <code>$path-&gt;getOffers()</code> which returned a <code>PersistentCollection</code> instead of what I thought is forced (an <code>ArrayCollection</code> of Offers).  Anyway, inside the current table, I have two entries: two offers to one path.  <code>$path-&gt;getOffers()</code> is returning a <code>PersistantCollection</code> of a <code>PathOffer</code> which only has one <code>Offer</code> attatched and not both.</p>
  
  <p>My question is how to really use these types of relations?  Because I need it with many other aspects of this project I'm working on (many M:M collections also need to be positioned)</p>
  
  <p>My code is below!</p>
  
  <h2>Path.php</h2>
  
  <pre><code>[..]
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="path")
   */
  class Path
  {
      /**
       * @var integer
       *
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      protected $id;
  
      /**
       * @ORM\OneToMany(targetEntity="PathOffer", mappedBy="offer", cascade={"all"})
       */
      protected $offers;
  
  [..]
  </code></pre>
  
  <h2>PathOffer.php</h2>
  
  <pre><code>[..]
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="path_offer")
   */
  class PathOffer
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      protected $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="Path", inversedBy="offers", cascade={"all"})
       */
      protected $path;
  
      /**
       * @ORM\ManyToOne(targetEntity="Offer", inversedBy="offers", cascade={"all"})
       */
      protected $offer;
  
      /**
       * @ORM\Column(type="integer")
       */
      protected $pos;
  
  [..]
  </code></pre>
  
  <h2>Offer.php</h2>
  
  <pre><code>[..]
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="offer")
   */
  class Offer
  {
      /**
       * @var integer
       *
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      protected $id;
  
      /**
       * @var \ZGoffers\MainBundle\Entity\PathOffer
       *
       * @ORM\OneToMany(targetEntity="PathOffer", mappedBy="path", cascade={"all"})
       */
      protected $paths;
  
  [..]
  </code></pre>