Update new DataTable row value to database

Update new DataTable row value to database

menashemenashe Posts: 164Questions: 38Answers: 2

I have the following:

The Low Price field (which is a database column on the Packaging table) on the Packaging row is updated dynamically as a row in the Prices (child) table is modified (or added).

How can I save that table value to the database?

This question has an accepted answers - jump to answer

Answers

  • menashemenashe Posts: 164Questions: 38Answers: 2
    Answer ✓

    I actually came up with a much more elegant solution! The Lowest Price field is no longer in the database; it is "virtual".

    I thought that I needed it in the database to display the Lowest Price BEFORE the Price (child) rows were expanded.

    But, instead, I now generate it as a column of the Packaging table!

        ->leftJoin('(SELECT packaging_id, min(price) as lowest_price FROM prices WHERE prices.date > now() - INTERVAL \'90 days\' GROUP BY packaging_id) lowest', 'lowest.packaging_id', '=', 'packaging.id')
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Awesome - great to hear you found a solution.

    Allan

Sign In or Register to comment.