CakePHP 1.3 でこのクエリを作成する方法
SELECT "Redeem_log"."benefit_id", count("Redeem_log"."benefit_id") as JUMLAH FROM "redeem_logs" "Redeem_log"
LEFT JOIN "benefits" "Benefit" ON ("Redeem_log"."benefit_id" = "Benefit"."id")
LEFT JOIN "merchants" "Merchant" ON ("Benefit"."merchant_id" = "Merchant"."id")
LEFT JOIN "merchant_types" "Merchant_type" ON ("Merchant"."merchant_type_id" = "Merchant_type"."id")
WHERE "Redeem_log"."benefit_id" IS NOT NULL AND ("Merchant_type"."merchant_type"='lokal' OR "Merchant_type"."merchant_type"='nasional') GROUP BY "Redeem_log"."benefit_id" ORDER BY "JUMLAH" DESC
私はbegsTO、hasMany、またはectを使用したくありません
var $belongsTo = array(
'Benefit' => array('className' => 'Benefit', 'foreignKey' => 'benefit_id'),
'Merchant' => array('className' => 'Merchant', 'foreignKey' => 'merchant_id')
);
左結合は次のようなものです:
SELECT "Redeem_log"."benefit_id", count("Redeem_log"."benefit_id") as JUMLAH
FROM "redeem_logs" "Redeem_log"
LEFT JOIN "benefits" "Benefit" ON ("Redeem_log"."benefit_id" = "Benefit"."id")
LEFT JOIN "merchants" "Merchant" ON ("Redeem_log"."merchant_id" = "Merchant"."id")
WHERE "Redeem_log"."benefit_id" IS NOT NULL GROUP BY "Redeem_log"."benefit_id"
ORDER BY "JUMLAH" DESC