Question

I'm not sure if this question is about MySQL db or about the framework. I think both.

So, my code below refreshes the table, but removes the other related records from another tables. The code below is in Kohana3 framework.

ORM::factory ( 'deal' ) ->delete_all (); //removes data
    foreach ( $deals as $deal )
    {
      //refreshes the Deals table row by row
      $orm_deal = ORM::factory ( 'Deal' );
      //... apply some values
      $orm_deal = ->save ();
    }

The problem: I don't want to remove records from another tables. Is it possible to "renew" Deals table by newer data if that "fresh" records in Deals would be absolutely compatible with the related records, no chains will be lost. I don't want to change the structure of the db and foreign keys connections. Also I don't want to change any relations in the Model. Do I have any other choice? Thank you.

Was it helpful?

Solution

There is no way to "refresh" table data.

As far as I understand - your deals array could differ from the table content (some array records are new, some table records are old and have to be deleted, some records have to be just updated).

Your way is the most correct in such a case. Delete all records from the table, then fill the table with new records.

If you want to really "refresh" table data with the new one you have to write a function which would compare each record (if this record is in table or not) and after comparsion delete old record, insert new record or update old record with new data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top