title: Symfony | Doctrine Help Needed - Inserting in Multiple Tables
body: <p>I have 3 tables as:</p>
  
  <ol>
  <li>products - product_id, product_name, price, type, create_time</li>
  <li>gateways - gateway_id, gateway_name, create_time</li>
  <li>mapping_product_gateways - mapping_id, gateway_id, product_id</li>
  </ol>
  
  <p>The products and gateways tables have nothing in common. No foreign keys etc. But when I create a product, I show the gateway selection field as multi-select field that is populated with data from gateways table. Once I hit the submit button to insert the product record, at that time all the selected gateway’s IDs are inserted in mapping_product_gateways table with the same product_id and selected gateways id.</p>
  
  <p>So after insertion the record may look like as:</p>
  
  <p>Products table record: </p>
  
  <p>1, Product 1, $10, , digital, 10/10/2013</p>
  
  <p>2, Product 2, $13, subscription, 01/01/2013</p>
  
  <p>Gateways table record:</p>
  
  <p>1, Paypal, 03/01/2014</p>
  
  <p>2, Credit Card, 01/01/2014</p>
  
  <p>3, 2Checkout, 02/01/2014</p>
  
  <p>So, mapping_product_gateways record may look like:</p>
  
  <p>mapping_id, gateway_id, product_id</p>
  
  <p>1, 2, 1</p>
  
  <p>2, 3, 1</p>
  
  <p>3, 1, 2</p>
  
  <p>3, 2, 2</p>
  
  <p>That means Product ID 1 has Gateways 2 &amp; 3 associated with it and Product ID 2 has Gateways 1 &amp; 2 associated with it.</p>
  
  <p>Since there's no direct relationship between the mapping and product table, how to build query in repository class to do search, insert, update of the record? Or do I need to create onetomany type of relationship n entity? </p>
  
  <p>I am totally confused..excuse me but am very new to symfony.</p>
  
  <p>Thanks</p>