Skip to content

Commit

Permalink
Generate 'exist' rules based on foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Faryshta authored and samdark committed Jul 15, 2015
1 parent 4b5864e commit 6b74472
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ public function generateRules($table)
// doesn't support unique indexes information...do nothing
}

// Exist rules for foreign keys.
foreach ($table->foreignKeys as $refs) {
$refClassName = $this->generateClassName($refs[0]);
unset($refs[0]);
$rules[] = "[['" . implode("', '", array_keys($refs)) . "'], "
. "'exist', "
. "'skipOnError' => true, "
. "'targetClass' => $refClassName::className(), "
. "'targetAttributes' => ['"
. implode("', '", array_values($refs))
. "']],";
}

return $rules;
}

Expand Down

2 comments on commit 6b74472

@samdark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#64

@cebe
Copy link
Member

@cebe cebe commented on 6b74472 Jul 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipOnEmpty is true by default so this is not so much of a problem. at least it is in no way "horrible" :)

Please sign in to comment.