Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding methods in Table to validate entities
  • Loading branch information
lorenzo committed Dec 23, 2013
1 parent 8d5a641 commit 2e4fd8c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Cake/ORM/Table.php
Expand Up @@ -1517,6 +1517,10 @@ public function marshaller($safe = false) {
return new Marshaller($this, $safe);
}

public function entityValidator($type) {
return new EntityValidator($this, $type);
}

/**
* Create a new entity + associated entities from an array.
*
Expand Down Expand Up @@ -1588,6 +1592,22 @@ public function newEntities(array $data, $associations = null) {
return $marshaller->many($data, $associations);
}

public function validate($entity, $associations = null, $type = 'default') {
if ($associations === null) {
$associations = $this->_associated->keys();
}
$entityValidator = $this->entityValidator($type);
return $entityValidator->one($entity);
}

public function validateMany($entity, $associations = null, $type = 'default') {
if ($associations === null) {
$associations = $this->_associated->keys();
}
$entityValidator = $this->entityValidator($type);
return $entityValidator->many($entity);
}

/**
* Get the Model callbacks this table is interested in.
*
Expand Down

0 comments on commit 2e4fd8c

Please sign in to comment.