このテーブル構造を考えると、
categories{id}
product_models{id, category_id}
products{product_model_id, category_id}
これはすでに入力されていますが、product_models.category_id、products.category_idおよびproducts.product_model_idすべてが に設定されNULLている場合、次のようにして、すべてを「接続」する単一のクエリが必要です。
- allをテーブル
product_models.category_idのランダムな値に設定しますcategories - allをテーブル
products.product_model_idのランダムな値に設定しますproduct_models - each
products.category_idを、新しく割り当てられたproduct_modelsレコードの category_id の値に設定します。
SINGLEクエリで実行できますか?