Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Closure generators to access generated attributes #311

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -502,7 +498,7 @@ public function isPendingOrSaved($object)
public function deleteSaved()
{
$exceptions = array();
foreach ($this->saved as $object) {
foreach (array_reverse($this->saved) as $object) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be more efficient for us to just add them to the starts of the saved array in the first place rather than reversing the entire array at this point?

Also, this is a change in behaviour, so should really be going into 2.2, rather than 2.1.

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually work in the way you expect it to. I'm pretty sure the order here is random since we're storing the objects with their hashes as keys, so php will iterate over them alphabetically by hash (so the order will appear random).

Copy link
Member

Choose a reason for hiding this comment

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

try {
if (!$this->delete($object)) {
throw new DeleteFailedException(get_class($object));
Expand Down Expand Up @@ -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;
Expand Down