codeigniter
アクティブなレコード フォームでクエリを実行すると、異なる結果が得られますMyPhpAdmin
を使用して実行される次のクエリMyPhpAdmin
SELECT * FROM (`ingredients`) LEFT JOIN `product_ingredients` ON `ingredients`.`ingredient_id` = `product_ingredients`.`ingredient_id` AND `product_id` = 46
返される両方の成分レコードの成分 ID を含む望ましい結果が得られます。
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => 2 [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
Codeigniter
しかし、次のコードで Active record を使用してこのクエリを実行すると:
$this->db->select('*');
$this->db->join('product_ingredients', 'ingredients.ingredient_id = product_ingredients.ingredient_id AND `product_id` = 46', 'left');
$query = $this->db->get('ingredients');
次に、結果の配列には、次の 2 番目の成分結果の成分 ID がありません。
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
どんな助けでも本当にありがたいです...