Example #1
0
 /**
  * Gets the primary keys of the has many values
  * @param Model $model Model of the has many field
  * @param string $foreignKey Name of the foreign key to this model
  * @param integer $id Value for the foreign key
  * @return array Array with the primary key of the has many value as key and value
  */
 private function findOldHasManyAndBelongsTo($model, $foreignKey, $id)
 {
     $condition = new SimpleCondition(new FieldExpression($foreignKey), new ScalarExpression($id), Condition::OPERATOR_EQUALS);
     $statement = new SelectStatement();
     $statement->addTable(new TableExpression($model->getName()));
     $statement->addField(new FieldExpression(ModelTable::PRIMARY_KEY));
     $statement->addCondition($condition);
     $result = $this->executeStatement($statement);
     $model->clearCache();
     $oldHasMany = array();
     foreach ($result as $record) {
         $oldHasMany[$record[ModelTable::PRIMARY_KEY]] = $record[ModelTable::PRIMARY_KEY];
     }
     return $oldHasMany;
 }