Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Many to Many Cascade Delete Ignored
  • Hey guys - another ORM question.
    I have three models: Inventory_import
    Inventory_main
    Inventory_equipment I have a table for each, and a many to many table for associating inventory_main with inventory_equipment.
    However, what I am doing is importing new inventory into Inventory_import, then copying it ove to Inventory_main. They share the same association. The only difference in the ORM is that I have cascade delete set to false for import so it doesn't remove the equipment when I delete the import records. However, this is being ignored.
    $existing = Model_Inventory_Import::find('all');
    foreach($existing as $ex)
    {
     $ex->delete();
    }
    

    The many to many looks like this for Inventory_Import:
         protected static $_many_many = array(
         'equipment' => array(
             'key_from' => 'vin',
             'key_through_from' => 'vehicle_vin',
             'table_through' => 'inventory_equipment_association', 
             'key_through_to' => 'equipment_id',
             'model_to' => 'Model_Inventory_Equipment',
             'key_to' => 'equipment_id',
             'cascade_save' => true,
             'cascade_delete' => false,
         )
     );
    

    Any ideas as to why it's still deleting the equipment when I delete the Import records?
  • I'll try, hope wthis will work : ). The documentation says that "Specifies a many-to-many relationship to another model. The target model will have the same type of relationship in the other direction. ". Can you check this?
  • Yes, I've tried setting it up various ways. Right now it works like this:
    protected static $_many_many = array(
         'vehicles' => array(
             'key_from' => 'equipment_id',
             'key_through_from' => 'equipment_id',
             'table_through' => 'inventory_equipment_association', 
             'key_through_to' => 'vehicle_vin',
             'model_to' => 'Model_Inventory_Main',
             'key_to' => 'vin',
             'cascade_save' => true,
             'cascade_delete' => false,
         ),
         'vehicles2' => array(
       'key_from' => 'equipment_id',
             'key_through_from' => 'equipment_id',
             'table_through' => 'inventory_equipment_association', 
             'key_through_to' => 'vehicle_vin',
             'model_to' => 'Model_Inventory_Import',
             'key_to' => 'vin',
             'cascade_save' => true,
             'cascade_delete' => false,
      )
     ); 
    

    I also tried finding and deleting all records from Model_Inventory_Main, which also cascade deleted all records, which is what it is supposed to do.

Howdy, Stranger!

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

In this Discussion