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

Model_Purchase_Item::get_reference_paranoid() could break outside use of Jam_Behavior_Paranoid::filter() #5

Closed
hkdobrev opened this issue Nov 7, 2013 · 1 comment
Assignees

Comments

@hkdobrev
Copy link
Contributor

hkdobrev commented Nov 7, 2013

Model_Purchase_Item::get_reference_paranoid() looks like this:

/**
 * Get the reference even if it was deleted
 * @return Jam_Model
 */
public function get_reference_paranoid()
{
  Jam_Behavior_Paranoid::filter(Jam_Behavior_Paranoid::ALL);
  $reference = $this->get_insist('reference');
  Jam_Behavior_Paranoid::filter(Jam_Behavior_Paranoid::NORMAL);

  return $reference;
}

If you are using Jam_Behavior_Paranoid::filter() in an outside scope using Model_Purchase_Item::price() or Model_Purchase_Item::compute_price() it would not work as expected.

Imagine the following scenario:

Jam_Behavior_Paranoid::filter(Jam_Behavior_Paranoid::ALL);
foreach ($store_purchases as $store_purchase)
{
  $store_purchase->items[0]->price();
  ...
}
Jam_Behavior_Paranoid::filter(Jam_Behavior_Paranoid::NORMAL);

The price() call would actually set the paranoid filter back to normal even on the first iteration.

get_reference_paranoid() should use the old-school deleted() builder method.

@ghost ghost assigned hkdobrev and ivank Nov 7, 2013
@hkdobrev
Copy link
Contributor Author

hkdobrev commented Nov 7, 2013

Fixed in 5ebcecc

@hkdobrev hkdobrev closed this as completed Nov 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants