Permalink
Browse files

BackwardsCompatibilityBreak - renamed fRecordSet::create() to fRecord…

…Set::build(), removed fRecordSet::createEmpty(), renamed fRecordSet::createFromObjects() to fRecordSet::buildFromRecords() and added a new first parameter, renamed fRecordSet::createFromPrimaryKeys() to fRecordSet::buildFromPrimaryKeys(), renamed fRecordSet::createFromSQL() to fRecordSet::buildFromSQL()
  • Loading branch information...
wbond committed Aug 26, 2008
1 parent a905fb5 commit 90ac23530d1c257f20e814c53bf4f6be706196e8
@@ -303,7 +303,7 @@ static private function createNewAlias($table, &$used_aliases)
* @internal
*
* @param string $table The table any ambigious column references will refer to
* @param array $order_bys The array of order bys to use (see {@link fRecordSet::create()} for format)
* @param array $order_bys The array of order bys to use (see {@link fRecordSet::build()} for format)
* @return string The SQL ORDER BY clause
*/
static public function createOrderByClause($table, $order_bys)
@@ -394,7 +394,7 @@ static public function createPrimaryKeyWhereClause($table, $table_alias, &$value
* @internal
*
* @param string $table The table any ambigious column references will refer to
* @param array $conditions The array of conditions (see {@link fRecordSet::create()} for format)
* @param array $conditions The array of conditions (see {@link fRecordSet::build()} for format)
* @return string The SQL WHERE clause
*/
static public function createWhereClause($table, $conditions)
@@ -54,7 +54,7 @@ static public function associateRecords($class, &$related_records, $related_clas
$new_primary_keys[] = $primary_key;
}
$records = fRecordSet::createFromPrimaryKeys($related_class, $primary_keys);
$records = fRecordSet::buildFromPrimaryKeys($related_class, $primary_keys);
self::setRecords($class, $related_records, $related_class, $records, $route);
$records->flagForAssociation();
}
@@ -111,7 +111,7 @@ static public function constructRecordSet($class, &$values, &$related_records, $
// Determine how we are going to build the sequence
if ($values[$relationship['column']] === NULL) {
$record_set = fRecordSet::createEmpty($related_class);
$record_set = fRecordSet::buildFromRecords($related_class, array());
} else {
// When joining to the same table, we have to use a different column
@@ -123,7 +123,7 @@ static public function constructRecordSet($class, &$values, &$related_records, $
$where_conditions = array($table . '.' . $column . '=' => $values[$relationship['column']]);
$order_bys = self::getOrderBys($class, $related_class, $route);
$record_set = fRecordSet::create($related_class, $where_conditions, $order_bys);
$record_set = fRecordSet::build($related_class, $where_conditions, $order_bys);
}
self::setRecords($class, $related_records, $related_class, $record_set, $route);
@@ -231,7 +231,7 @@ static public function determineRequestFilter($class, $related_class, $route)
* @param mixed $class The class name or instance of the class this ordering rule applies to
* @param string $related_class The related class the ordering rules apply to
* @param string $route The route to the related table, should be a column name in the current table or a join table name
* @return array An array of the order bys (see {@link fRecordSet::create()} for format)
* @return array An array of the order bys (see {@link fRecordSet::build()} for format)
*/
static public function getOrderBys($class, $related_class, $route)
{
@@ -390,12 +390,7 @@ static public function populateRecords($class, &$related_records, $related_class
fRequest::unfilter();
}
if (empty($records)) {
$record_set = fRecordSet::createEmpty($related_class);
} else {
$record_set = fRecordSet::createFromObjects($records);
}
$record_set = fRecordSet::buildFromRecords($related_class, $records);
$record_set->flagForAssociation();
self::setRecords($class, $related_records, $related_class, $record_set, $route);
}
@@ -535,7 +530,7 @@ static public function reflect($class, &$signatures, $include_doc_comments)
* @param mixed $class The class name or instance of the class this ordering rule applies to
* @param string $related_class The related class we are getting info from
* @param string $route The route to the related table, this should be a column name in the current table or a join table name
* @param array $order_bys An array of the order bys for this table.column combination (see {@link fRecordSet::create()} for format)
* @param array $order_bys An array of the order bys for this table.column combination (see {@link fRecordSet::build()} for format)
* @return void
*/
static public function setOrderBys($class, $related_class, $route, $order_bys)
@@ -608,7 +603,7 @@ static public function storeOneToMany(&$values, $relationship, $record_set)
);
$related_class = $record_set->getClassName();
$existing_records = fRecordSet::create($related_class, $where_conditions);
$existing_records = fRecordSet::build($related_class, $where_conditions);
$existing_primary_keys = $existing_records->getPrimaryKeys();
$new_primary_keys = $record_set->getPrimaryKeys();
@@ -75,7 +75,7 @@ static public function configure($class_name)
* @param integer $offset The offset to use before limiting
* @return fRecordSet A set of {@link fActiveRecord} objects
*/
static public function create($class_name, $where_conditions=array(), $order_bys=array(), $limit=NULL, $offset=NULL)
static public function build($class_name, $where_conditions=array(), $order_bys=array(), $limit=NULL, $offset=NULL)
{
self::configure($class_name);
@@ -124,52 +124,18 @@ static public function create($class_name, $where_conditions=array(), $order_bys
}
/**
* Creates an empty {@link fRecordSet}
*
* @throws fValidationException
* @internal
*
* @param string $class_name The type of object to create
* @return fRecordSet A set of {@link fActiveRecord} objects
*/
static public function createEmpty($class_name)
{
self::configure($class_name);
$table_name = fORM::tablize($class_name);
settype($primary_keys, 'array');
$primary_keys = array_merge($primary_keys);
$sql = 'SELECT ' . $table_name . '.* FROM ' . $table_name . ' WHERE ';
$sql .= fORMDatabase::getInstance()->escapeBoolean(TRUE) . ' = ' . fORMDatabase::getInstance()->escapeBoolean(FALSE);
return new fRecordSet($class_name, fORMDatabase::getInstance()->translatedQuery($sql));
}
/**
* Creates an {@link fRecordSet} from an array of records
*
* @throws fValidationException
* @internal
*
* @param array $records The records to create the set from, the order of the record set will be the same as the order of the array.
* @param string $class_name The type of object to create
* @param array $records The records to create the set from, the order of the record set will be the same as the order of the array.
* @return fRecordSet A set of {@link fActiveRecord} objects
*/
static public function createFromObjects($records)
static public function buildFromRecords($class_name, $records)
{
if (empty($records)) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
'You can not build a record set from an empty array of records'
)
);
}
$class_name = get_class($records[0]);
self::configure($class_name);
$table_name = fORM::tablize($class_name);
@@ -208,6 +174,11 @@ static public function createFromObjects($records)
$i++;
}
// Empty sets have SQL that won't return anything
if (sizeof($records) == 0) {
$sql .= " 0 = 1";
}
$result = new fResult('array');
$result->setResult(array());
$result->setReturnedRows(sizeof($records));
@@ -228,10 +199,10 @@ static public function createFromObjects($records)
*
* @param string $class_name The type of object to create
* @param array $primary_keys The primary keys of the objects to create
* @param array $order_bys The column => direction values to use for sorting (see {@link fRecordSet::create()} for format)
* @param array $order_bys The column => direction values to use for sorting (see {@link fRecordSet::build()} for format)
* @return fRecordSet A set of {@link fActiveRecord} objects
*/
static public function createFromPrimaryKeys($class_name, $primary_keys, $order_bys=array())
static public function buildFromPrimaryKeys($class_name, $primary_keys, $order_bys=array())
{
self::configure($class_name);
@@ -330,7 +301,7 @@ static public function createFromPrimaryKeys($class_name, $primary_keys, $order_
* @param string $non_limited_count_sql An SQL statement to get the total number of rows that would have been returned if a LIMIT clause had not been used. Should only be passed if a LIMIT clause is used.
* @return fRecordSet A set of {@link fActiveRecord} objects
*/
static public function createFromSQL($class_name, $sql, $non_limited_count_sql=NULL)
static public function buildFromSQL($class_name, $sql, $non_limited_count_sql=NULL)
{
self::configure($class_name);

0 comments on commit 90ac235

Please sign in to comment.