Skip to content

Commit

Permalink
Sets accessibleFields for all fields by default.
Browse files Browse the repository at this point in the history
This change makes it easier for the Shell to inject new DB records with a pre-defined primary key field from the seed data. This is essential if you are manually building up relationships between tables.
  • Loading branch information
beporter committed Oct 26, 2015
1 parent 58f1fff commit cb58dad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ $data = [
/**
* The _entityOptions array is passed to Table::newEntity() and
* Table::patchEntity(). It can be used to disable validation.
*
* Also be aware that the Shell sets
* `['accessibleFields' => ['*' => true]]` by default in order to
* more easily "prime" new Entities with all of the values
* specified in $data, including fixed primary keys. This bypasses
* your normal Entity `::$_accessible` settings, so it's good to
* be aware of this if you're using a seed to "refresh" existing
* data.
*/
//'_entityOptions' => [
// 'validate' => false,
Expand Down
7 changes: 4 additions & 3 deletions src/Shell/BasicSeedShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function entityGenerator(
) {
$defaultOptions = [
'validate' => true,
'accessibleFields' => ['*' => true],
];
$options = $options + $defaultOptions;

Expand All @@ -204,8 +205,7 @@ public function entityGenerator(
}

} else {
$entity = $Table->newEntity([], $options);
$entity->set($r, ['guard' => false]);
$entity = $Table->newEntity($r, $options);
$entity->isNew(true);
}

Expand All @@ -217,7 +217,7 @@ public function entityGenerator(
if ($errors) {
$this->printValidationErrors(
$Table->alias(),
$key,
$id,
$errors
);

Expand All @@ -241,6 +241,7 @@ public function entityGenerator(
public function importTable(Table $Table, $records, array $options = []) {
$defaultOptions = [
'checkRules' => true,
'checkExisting' => true,
];
$options = $options + $defaultOptions;

Expand Down

0 comments on commit cb58dad

Please sign in to comment.