Skip to content

Commit

Permalink
Make SchemaValidator catch errors such as very invalid schema using o…
Browse files Browse the repository at this point in the history
…nly part of the primary key for join columns
  • Loading branch information
beberlei committed Oct 15, 2011
1 parent 3dc30de commit a82bffb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ public function validateMapping()
"has to be a primary key column.";
}
}

if (count($targetClass->identifier) != count($assoc['joinTable']['inverseJoinColumns'])) {
$ce[] = "The inverse join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " .
"have to match to ALL identifier columns of the target entity '". $targetClass->name . "'";
}

if (count($class->identifier) != count($assoc['joinTable']['joinColumns'])) {
$ce[] = "The join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " .
"have to match to ALL identifier columns of the source entity '". $class->name . "'";
}

} else if ($assoc['type'] & ClassMetadataInfo::TO_ONE) {
foreach ($assoc['joinColumns'] AS $joinColumn) {
$targetClass = $cmf->getMetadataFor($assoc['targetEntity']);
Expand All @@ -167,6 +178,11 @@ public function validateMapping()
"has to be a primary key column.";
}
}

if (count($class->identifier) != count($assoc['joinColumns'])) {
$ce[] = "The join columns of the association '" . $assoc['fieldName'] . "' " .
"have to match to ALL identifier columns of the source entity '". $class->name . "'";
}
}
}

Expand Down

0 comments on commit a82bffb

Please sign in to comment.