Permalink
Browse files

bug #306 - add support to filterByObject method generator for collect…

…ions with composite foreign keys
  • Loading branch information...
1 parent 9d0251f commit e16cf6476ac7a04513783c75ffc789ea881f5c30 David Morfin committed Mar 2, 2012
Showing with 20 additions and 6 deletions.
  1. +20 −6 generator/lib/builder/om/QueryBuilder.php
@@ -973,15 +973,29 @@ public function filterBy$relationName($objectName, \$comparison = null)
->addUsingAlias($localColumnConstant, {$objectName}->toKeyValue('PrimaryKey', '$foreignColumnName'), \$comparison);";
}
$script .= "
- } else {";
- if ($fk->isComposite()) {
- $script .= "
- throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');";
- } else {
+ } elseif ($objectName instanceOf PropelCollection) {
+ if ({$objectName}->isEmpty()) {
+ return \$this->add(null, '1<>1', Criteria::CUSTOM);
+ }
+ foreach ({$objectName} as \$object) {";
+ $i = 0;
+ foreach ($fk->getLocalForeignMapping() as $localColumn => $foreignColumn) {
+ $localColumnObject = $table->getColumn($localColumn);
+ $foreignColumnObject = $fkTable->getColumn($foreignColumn);
$script .= "
- throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');";
+ \$cton$i = \$this->getNewCriterion(" . $this->getColumnConstant($localColumnObject) . ", \$object->get" . $foreignColumnObject->getPhpName() . "(), \$comparison);";
+ if ($i>0) {
+ $script .= "
+ \$cton0->addAnd(\$cton$i);";
+ }
+ $i++;
}
$script .= "
+ \$this->addOr(\$cton0);
+ }
+ return \$this;
+ } else {
+ throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');
}
}
";

0 comments on commit e16cf64

Please sign in to comment.