Skip to content

Instantly share code, notes, and snippets.

@jacobch
Created August 12, 2010 01:08
Show Gist options
  • Save jacobch/520118 to your computer and use it in GitHub Desktop.
Save jacobch/520118 to your computer and use it in GitHub Desktop.
<?php
class DBObject {
public function getManyMany($class,$where = false,$options = array()){
$table = static::_table();
$join = $class::_table();
if (strnatcmp($table, $join))
$join_table = sprintf('%s_%s', $join, $table);
else
$join_table = sprintf('%s_%s', $table, $join);
$result = SqlQuery::select('*')
->from(static::_table())
->join($join_table, sprintf('%s.id = %s.%s_id', $table, $join_table, $table))
->join($join, sprintf('%s.id = %s.%s_id', $join, $join_table, $join))
->where($class::_where($where))
->order_by($class::_order($options['order']))
->limit($options['limit'])
->run();
$object = new $class();
foreach ($result as $key => $value){
$object->_array[$key] = new $class(false, $value, $options);
$object->_array[$key]->info[$class::$_id] = $value[$join.'_id'];
}
return $object;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment