Created
August 12, 2010 01:08
-
-
Save jacobch/520118 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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