Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - Removed ability to preload related reco…
Browse files Browse the repository at this point in the history
…rds for a record set due to ever increasing complexity
  • Loading branch information
wbond committed Apr 12, 2012
1 parent fb8ef2f commit 1fd0f7c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 328 deletions.
11 changes: 1 addition & 10 deletions classes/database/object_relational_mapping/fActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __call($method_name, $parameters)
}

// This will prevent quiet failure
if (($action == 'set' || $action == 'associate' || $action == 'inject') && sizeof($parameters) < 1) {
if (($action == 'set' || $action == 'associate') && sizeof($parameters) < 1) {
fCore::toss(
'fProgrammerException',
fGrammar::compose(
Expand Down Expand Up @@ -137,15 +137,6 @@ public function __call($method_name, $parameters)
}
return fORMRelated::constructRecord($this, $this->values, $subject);

case 'inject':
$subject = fGrammar::singularize($subject);
$subject = fGrammar::camelize($subject, TRUE);

if (isset($parameters[1])) {
return fORMRelated::setRecords($this, $this->related_records, $subject, $parameters[0], $parameters[1]);
}
return fORMRelated::setRecords($this, $this->related_records, $subject, $parameters[0]);

case 'link':
$subject = fGrammar::singularize($subject);
$subject = fGrammar::camelize($subject, TRUE);
Expand Down
13 changes: 5 additions & 8 deletions classes/database/object_relational_mapping/fORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,16 @@ static public function registerHookCallback($class, $hook, $callback)
);

static $invalid_replace_hooks = array(
'replace::enableDebugging()',
'replace::assign()',
'replace::configure()',
'replace::constructInsertSQL()',
'replace::constructPrimaryKeyWhereClause()',
'replace::constructUpdateSQL()',
'replace::entify()',
'replace::format()',
'replace::enableDebugging()',
'replace::encode()',
'replace::get()',
'replace::loadFromIdentityMap()',
'replace::loadFromResult()',
'replace::retrieve()',
'replace::storeManyToManyAssociations()',
'replace::storeOneToManyRelatedRecords()'
'replace::prepare()',
'replace::set()'
);

if (!in_array($hook, $valid_hooks) && !$replace_hook) {
Expand Down
78 changes: 0 additions & 78 deletions classes/database/object_relational_mapping/fORMDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,84 +378,6 @@ static public function createPrimaryKeyWhereClause($table, $table_alias, &$value
}


/**
* Creates a where clause condition for primary keys of the table specified
*
* This method requires the $primary_keys parameter to be one of:
*
* - A scalar value for a single-column primary key
* - An array of values for a single-column primary key
* - An associative array of values for a multi-column primary key (column => value)
* - An array of associative arrays of values for a multi-column primary key (key => array(column => value)
*
* If you are looking to build a primary key where clause from the $values
* and $old_values arrays, please see {@link createPrimaryKeyWhereClause()}
*
* @throws fValidationException
* @internal
*
* @param string $table The table to build the where clause condition for
* @param string $table_alias The alias for the table
* @param mixed $primary_keys The primary key or keys to use in building the condition
* @return string A single WHERE clause condition (possibly in parentheses) representing the primary keys provided
*/
static public function createPrimaryKeyWhereCondition($table, $table_alias, $primary_keys)
{
$sql = '';

$primary_key_fields = fORMSchema::getInstance()->getKeys($table, 'primary');

// We have a multi-field primary key, making things kinda ugly
if (sizeof($primary_key_fields) > 1) {

// If the multi-field primary key is just a single primary key we'll convert it so we don't need lots of conditional code to generate SQL
if (!isset($primary_keys[0])) {
$primary_keys = array($primary_keys);
}

$sql .= '((';
$first = TRUE;
foreach ($primary_keys as $primary_key) {
if (!$first) {
$sql .= ') OR (';
}
for ($i=0; $i < sizeof($primary_key_fields); $i++) {
$field = $primary_key_fields[$i];
if ($i) {
$sql .= ' AND ';
}
$sql .= $table_alias . '.' . $field;
$sql .= fORMDatabase::prepareBySchema($table, $field, $primary_key[$field], '=');
}
$first = FALSE;
}
$sql .= '))';

// We have a single primary key field, making things nice and easy
} else {
$primary_key_field = $primary_key_fields[0];

// If we don't have an array of primary keys, just return a regular equation comparison
if (!is_array($primary_keys)) {
return $table_alias . '.' . $primary_key_field . fORMDatabase::prepareBySchema($table, $primary_key_field, $primary_keys, '=');
}

$sql .= $table_alias . '.' . $primary_key_field . ' IN (';
$first = TRUE;
foreach ($primary_keys as $primary_key) {
if (!$first) {
$sql .= ', ';
}
$sql .= fORMDatabase::prepareBySchema($table, $primary_key_field, $primary_key);
$first = FALSE;
}
$sql .= ')';
}

return $sql;
}


/**
* Creates a where clause from an array of conditions
*
Expand Down
4 changes: 1 addition & 3 deletions classes/database/object_relational_mapping/fORMRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,14 @@ static public function setOrderBys($class, $related_class, $route, $order_bys)
/**
* Sets the related records for many-to-many relationships
*
* @internal
*
* @param mixed $class The class name or instance of the class to get the related values for
* @param array &$related_records The related records existing for the {@link fActiveRecord} class
* @param string $related_class The class we are associating with the current record
* @param fRecordSet $records The records are associating
* @param string $route The route to use between the current class and the related class
* @return void
*/
static public function setRecords($class, &$related_records, $related_class, fRecordSet $records, $route=NULL)
static private function setRecords($class, &$related_records, $related_class, fRecordSet $records, $route=NULL)
{
$table = fORM::tablize($class);
$related_table = fORM::tablize($related_class);
Expand Down
Loading

0 comments on commit 1fd0f7c

Please sign in to comment.