Skip to content

Instantly share code, notes, and snippets.

@jippi
Created May 9, 2012 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jippi/2649806 to your computer and use it in GitHub Desktop.
Save jippi/2649806 to your computer and use it in GitHub Desktop.
diff --git lib/Cake/Model/Model.php lib/Cake/Model/Model.php
index ab12d98..8049dd1 100644
--- lib/Cake/Model/Model.php
+++ lib/Cake/Model/Model.php
@@ -1438,10 +1438,12 @@ class Model extends Object implements CakeEventListener {
* @param mixed $data Optional data array to assign to the model after it is created. If null or false,
* schema data defaults are not merged.
* @param boolean $filterKey If true, overwrites any primary key input with an empty value
+ * @param array $options
* @return array The current Model::data; after merging $data and/or defaults from database
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-create-array-data-array
*/
- public function create($data = array(), $filterKey = false) {
+ public function create($data = array(), $filterKey = false, $options = array()) {
+ $options = array_merge(array('defaults' => true), $options);
$defaults = array();
$this->id = false;
$this->data = array();
@@ -1449,7 +1451,7 @@ class Model extends Object implements CakeEventListener {
if ($data !== null && $data !== false) {
foreach ($this->schema() as $field => $properties) {
- if ($this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') {
+ if ($options['defaults'] && $this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') {
$defaults[$field] = $properties['default'];
}
}
@@ -2115,7 +2117,7 @@ class Model extends Object implements CakeEventListener {
if ($options['deep']) {
$validates = $this->validateAssociated($record, $options);
} else {
- $validates = $this->create($record) && $this->validates($options);
+ $validates = $this->create($record, false, array('defaults' => false)) && $this->validates($options);
}
$data[$key] = $this->data;
if ($validates === false || (is_array($validates) && in_array(false, $validates, true))) {
diff --git lib/Cake/Test/Case/Model/ModelWriteTest.php lib/Cake/Test/Case/Model/ModelWriteTest.php
index f931b7c..3a463ba 100644
--- lib/Cake/Test/Case/Model/ModelWriteTest.php
+++ lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -4238,7 +4238,7 @@ class ModelWriteTest extends BaseModelTest {
* @return void
*/
public function testSaveAllValidation() {
- $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
+ $this->loadFixtures('Post', 'Author', 'Comment', 'Article', 'Attachment');
$TestModel = new Post();
$data = array(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment