I have 3 tables as:
- products - product_id, product_name, price, type, create_time
- gateways - gateway_id, gateway_name, create_time
- mapping_product_gateways - mapping_id, gateway_id, product_id
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.
So after insertion the record may look like as:
Products table record:
1, Product 1, $10, , digital, 10/10/2013
2, Product 2, $13, subscription, 01/01/2013
Gateways table record:
1, Paypal, 03/01/2014
2, Credit Card, 01/01/2014
3, 2Checkout, 02/01/2014
So, mapping_product_gateways record may look like:
mapping_id, gateway_id, product_id
1, 2, 1
2, 3, 1
3, 1, 2
3, 2, 2
That means Product ID 1 has Gateways 2 & 3 associated with it and Product ID 2 has Gateways 1 & 2 associated with it.
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?
I am totally confused..excuse me but am very new to symfony.
Thanks