laravel - Converting sql to eloquent -
i'm trying write self join in eloquent, here in sql
select t2.id products t1, products t2 t1.id = 1 , t2.id != 1 , (t1.color_id = t2.color_id or t1.process_id = t2.process_id or t1.length_id = t2.length_id or t1.size_id = t2.size_id or t1.height_id = t2.height_id) order rand() limit 10
here have in eloquent:
product::join('products t2', 'products.id', '=', 't2.id') ->select('t2.id') ->where('products.id', 1) ->where('t2.id', '!=', 1) ->where(function($query){ $query->where('products.color_id', '=', 't2.color_id') ->orwhere('products.process_id', '=', 't2.process_id') ->orwhere('products.length_id', '=', 't2.length_id') ->orwhere('products.size_id', '=', 't2.size_id') ->orwhere('products.height_id', '=', 't2.height_id'); }) ->get();
i have yet add order , limit eloquent - trying results out first.
the problem eloquent it's producing 0 results, sql give me results expect, going wrong?
edit
i have modified query to:
product::join('products t2', 'products.id', '=', 't2.id') ->select('t2.id') ->where(function($query){ $query->where('products.color_id', '=', 't2.color_id') ->orwhere('products.process_id', '=', 't2.process_id') ->orwhere('products.length_id', '=', 't2.length_id') ->orwhere('products.size_id', '=', 't2.size_id') ->orwhere('products.height_id', '=', 't2.height_id'); }) ->get();
but still 0 results.
edit 2
here sql statement being run:
select `t2`.`id` `products` inner join `products` `t2` on `products`.`id` = `t2`.`id` ( `products`.`look_color_id` = ? or `products`.`process_id` = ? or `products`.`length_id` = ? or `products`.`size_id` = ? or `products`.`height_id` = ? )
Comments
Post a Comment