Ticket #1755 (closed defect: fixed)
Validate foreign key columns when valid relation type is set
| Reported by: | adamthehutt | Owned by: | jwage |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.0.6 |
| Component: | Validators | Version: | 1.0.4 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | yes | |
| Status: | Pending Core Response | Has Patch: | yes |
Description
Records with notnull foreign keys currently return false for isValid() when an unpersisted relation is set.
See attached test for examples.
Suggested (imperfect) fix:
I made the following change in Doctrine_Table::validateField(). Change:
if ($value === self::$_null) {
$value = null;
} else if ($value instanceof Doctrine_Record) {
$value = $value->getIncremented();
}
To:
if ($value === self::$_null) {
$value = null;
} else if ($value instanceof Doctrine_Record && $value->exists()) {
$value = $value->getIncremented();
} else if ($value instanceof Doctrine_Record) {
foreach($this->getRelations() as $relation) {
if($fieldName == $relation->getLocalFieldName() && get_class($value) == $relation->getClass()) {
return $errorStack;
}
}
}
Basically, if $value is a Doctrine_Record object, only grab the primary key if it exists. Otherwise, just make sure it's the right class. I realize this is far from perfect, but I think it's preferable to the current behavior.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.