In a Kohana query, I need to retrieve only one element having the same id. I have a method in the model:

public function next_products_images($id)
{
  return $this->where('product_image_product', '>=', $id-5)->limit(5)->find_all();  
  //for taking the previous five product pictures       
}  

but the problem is that, from all the above results, generated by the method, I need to have only the ones that have "product_image_product" distinct. Can this be done using Kohana ORM?

Thanks a lot!

有帮助吗?

解决方案

Does it work using a group by?

return $this->where('product_image_product', '>=', $id-5)->limit(5)->group_by('product_image_product')->find_all();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top