Ticket #1755 (closed defect: fixed)

Opened 7 months ago

Last modified 7 months ago

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

ValidateForeignKeysTestCase.php (2.2 KB) - added by adamthehutt 7 months ago.
test case

Change History

Changed 7 months ago by adamthehutt

test case

Changed 7 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [5296]) [1.0, 1.1] Fixes issue with validators not passing when a related object is set for a foreign key and the foreign key field is notnull (closes #1755)

Changed 7 months ago by jwage

  • milestone changed from 1.0.6 to 1.0.5

Changed 7 months ago by jwage

  • milestone changed from 1.0.5 to 1.0.6
Note: See TracTickets for help on using tickets.