From 0ff176cd2622279c9900b508fd084d76426fe92d Mon Sep 17 00:00:00 2001 From: Patrick McCarren Date: Sun, 31 Aug 2014 22:01:14 -0400 Subject: [PATCH 1/2] Delete objects in the reverse as they were created --- src/Factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory.php b/src/Factory.php index cace74b..7701551 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -502,7 +502,7 @@ public function isPendingOrSaved($object) public function deleteSaved() { $exceptions = array(); - foreach ($this->saved as $object) { + foreach (array_reverse($this->saved) as $object) { try { if (!$this->delete($object)) { throw new DeleteFailedException(get_class($object)); From c6cf2fe965fa02f609a15d60276ef74119b604a5 Mon Sep 17 00:00:00 2001 From: Patrick McCarren Date: Sun, 31 Aug 2014 22:02:41 -0400 Subject: [PATCH 2/2] Set the att value on the model once generated. This allows generators of the 'Closure' type to access attributes immediately after they are generated via the object that is passed in as the first paramater. --- src/Factory.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index 7701551..c39d48a 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -334,11 +334,7 @@ private function make($model, array $attr, $save) } // Get the factory attributes for that model - $attributes = $this->attributesFor($object, $attr); - - foreach ($attributes as $name => $value) { - $this->setAttribute($object, $name, $value); - } + $this->attributesFor($object, $attr); return $object; } @@ -579,6 +575,7 @@ public function attributesFor($object, array $attr = array()) // Prepare attributes foreach ($attributes as $key => $kind) { $attr[$key] = $this->generateAttr($kind, $object); + $this->setAttribute($object, $key, $attr[$key]); } return $attr;