Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
New relation set on object wasn't found.
  • Trying to figure out for the last 2 hours why I am getting this exception and I have no ideas why I get it... It happens here where I want to save belongs_to relation:

    $item->warehouse_location_from = $warehouse_location_from;
    $item->save();

    $warehouse_location_from is loaded from database via find($id) method and is loaded allright... ORM model for item is set like this:

    protected static $_belongs_to = array(
       'warehouse_location_from' => array(
           'key_from' => 'warehouse_location_id_from',
           'model_to' => 'Model_Warehouselocation',
           'key_to' => 'id',
       )
    );

    What am I missing here?
  • No idea.

    A grep on all Fuel code doesn't reveal that error message. Where does it come from, what generates it?
  • Ah, that's why I couldn't find it.

    It complains that it has a related object that is supposed to exist, buf when it does a find() using the objects' key, it can't find it.

    So where does your $warehouse_location_from come from? Since is_new() reports false on it, and yet the primary key of the object does not exist in the database.
  • It comes from here:

    $warehouse_location_from = \Model_Warehouselocation::find($item->product ? $item->product->warehouse_location_id : 1523);

    And the primary key's that load this exist in the DB. It happens with I 1523 and it exists... Even if I log it with Log::info($warehouse_location_from->name) it will log correctly but then fail with above message on this save()

    $item->warehouse_location_from = $warehouse_location_from;
    $item->save();


    This is from the log...

    $warehouse_location_from = \Model_Warehouselocation::find($item->product ? $item->product->warehouse_location_id : 1523);
    $item->warehouse_location_from = $warehouse_location_from;
    Log::info($warehouse_location_from->id.' '.$warehouse_location_from->name);
    $item->save();


    INFO - 2016-05-24 06:01:59 --> 1502 SKL ARHIV
    INFO - 2016-05-24 06:01:59 --> 1502 SKL ARHIV
    INFO - 2016-05-24 06:01:59 --> 1502 SKL ARHIV
    INFO - 2016-05-24 06:01:59 --> 1523 SKL ARHIV REG/05/SUPPLIES
    ERROR - 2016-05-24 06:01:59 --> Error - New relation set on Model_Goodstransferitem object wasn't found. in /Users/primozrome/Dropbox/www/dewesoftadmin/fuel/packages/orm/classes/belongsto.php on line 173





  • Ahh the problem was in some other relation. I have figured it our. Damn!!
  • ;-) These things happen. Glad you've got it sorted.
  • Yeah thanks for helping ;)

Howdy, Stranger!

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

In this Discussion