そのようなものを想像してみましょう:
SELECT * FROM products LEFT JOIN prices ON prices.PRODUCT_ID = products.ID;
これにより、次のようになります。
ID: 1; NAME: 'product with no price'; PRODUCT_ID: null; PRICE: null;
ID: 2; NAME: 'product with one price'; PRODUCT_ID: 2; PRICE: 1000;
ID: 3; NAME: 'product with two prices'; PRODUCT_ID: 3; PRICE: 2000;
ID: 3; NAME: 'product with two prices'; PRODUCT_ID: 3; PRICE: 2500;
このアルゴリズムは以下を生成する必要があります。
array:
product => (
[0]
id = 1
name = product with no price
prices = array()
[1]
id = 2
name = product with one price
prices = array(
product_id: 2,
price: 1000
)
[2]
id = 3
name = product with two prices
prices = array(
array(product_id: 3,
price: 2000),
array(product_id: 3,
price: 2500)
)
推移的な結合についても忘れないでください。つまり、価格 -> 製品ですが、commentOnPrice -> 価格 -> 製品の場合もあります。その複雑なアルゴリズムを作成することは可能ですか?