tags:

views:

584

answers:

2

I have a table (product_shoppingcart) with 4 columns :

id, product_id, shoppingcart_id, product_quantity.

I'm using Kohana's ORM.

I want to write a search query which returns all the rows where the shoppingcart_id column contains 1 (for example).

I already tried:

$arr = ORM::factory('product_shoppingcart')->where('shoppingcart_id',$shoppingcartID)->find_all();

but that doesn't work.

Can anyone please help me out?

A: 

Shouldnt your table be "product_shoppingcarts" or am I missing something?

sydlawrence
You can set $table_name = 'product_shoppingcart'; within the model if your table is named something else.
Ambirex
+1  A: 

Your example code should work, but perhaps the problem is that you're not iterating over your result set?

$results = ORM::factory('product_shoppingcart')
           ->where('shoppingcart_id', $shoppingcartID)
           ->find_all();
foreach ($results as $product_shoppingcart) {
  print Kohana::debug($product_shoppingcart->as_array());
}

If you have more than one row with that id, this should give you a result iterator in $results, which you then walk with the foreach loop. I have lots of examples of similar working code, if you're still not able to get it working.

bharat