0

i have an array like this:

$arr = (1, 3, 87, 200);

I wanna get the Object for these IDs only

ca I do it like this:

$object = new Object($arr);

foreach($object as $o)
{
$o->user->get()
}
Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
John Smith
  • 47
  • 8

1 Answers1

1

You can use the where_in method.

$arr = array(1, 3, 87, 200);

$o = new Object();
$o->where_in('id', $arr);
$o->get();

// When $o->get() is called, all records where
// the id is 1, 3, 87 or 200 will be returned

If you wanted to order them you could use the following, before calling get().

$o->order_by("column_1", "column_2");

For more bits you can do prior to get, see the manual page

http://datamapper.wanwizard.eu/pages/get.html

Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
  • THANK YOU. I have 1 more question. it works now. but objects are ordered by id, and not by the $arr. how could I now order objects by the array ? – John Smith Apr 12 '13 at 14:12