Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FrozenObject error when saving object
  • Hi there, I have this 3 models (need some extra data on many_to_many table):
    class Model_Product_Budget extends Orm\Model {
     protected static $_properties = array('id','product_code','budget_id','price','qty','created_at','updated_at',);
     protected static $_table_name = 'products_budgets';
     protected static $_belongs_to = array('product', 'budget');
    }
    
    class Model_Budget extends Orm\Model 
    { 
     protected static $_belongs_to = array('client');
     protected static $_has_many = array('product_budget');
     
     protected static $_many_many = array(
      'product' => array(
       'table_through' => 'products_budgets',
       'key_through_from' => 'budget_id',
       'key_through_to' => 'product_code',
       'key_to' => 'product_code',
       'cascade_save' => false
      )
     );
     protected static $_properties = array('id', 'client_id', 'message', 'subtotal', 'discount', 'total', 'created_at', 'updated_at', 'sent','hash',);
    }
    
    class Model_Client extends Orm\Model 
    { 
     protected static $_has_many = array('budget');
     protected static $_properties = array('id','first_name','last_name','email','company','phone','address_street','address_number','city','created_at', 'updated_at','cuit',);
    }
    

    ... and this, into a controller:
    $budget = Model_Budget::find($id);
    $budget->subtotal = $subtotal;
    $budget->total = $total;
    $budget->discount = $discount;
    $budget->save();
    

    And then, I get this error: Orm\FrozenObject [ Error ]: No changes allowed. PKGPATH/orm/classes/model.php @ line 698 And this prior non fatal error: Notice: Undefined index: budget in PKGPATH/orm/classes/model.php @ line 1203 What's going on? Where is my mistake? This was OK on v1.0, but stop working when I updated to 1.1/master, and was the same when checked out 1.1/develop Thank you!
  • Ok, after a couple of hours messing with the code, I solved it. I just need to update some parent object properties, so I've used $budget->save(false), to not cascade save. I didn't know save() had arguments until looking on ORM code; it's not on the docs. Don't know if there is an error on my code, or a bug. It's more likely I'm missing something or doing something wrong. I hope this to be useful for anyone. Thanks!
  • Only reason I can think of this might happen is when you tried to save, caught an exception and retried saving. But I think I already put safeguards against that in place. Don't have the time to research this now, if you want to be sure I don't forget put it in the issue tracker on Github. I don't check the forums for open bugs.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion