Here's the bulk of my code. Before all that code happens, here's the logic:
I query the database for $dbLink and convert it into an array via the array command (resulting variable: $dbLinkArrayOriginal). I've already logged the Array so I know the format is right, I also queried an API that converts to an array with the same form as $dbLinkArrayOriginal the queried array gets stored as $dbLinkArray. all of these are in a foreach, there are a ton of links that need to be updated.
I ran the script several times to make sure it works. If there are no changes, nothing should be updated.
$updateLinks = array_diff($dbLinkArray, $dbLinkArrayOriginal); $dbLink->fill($updateLinks); Log::info('1st LOG Original: '.$dbLinkArrayOriginal['link_text'].' New: '.$dbLinkArray['link_text']); Log::info('2nd Log Dirty: '.implode(', ', $dbLink->get_dirty())); $dbLink->save(); Log::info('3rd Log Supposed to be changed: '.implode(', ',array_keys($updateLinks)));
Results of Logs
I ran my above update script several times and made these observations:
1st Log: the results don't match (they're different) and when I use the same update script, the $dbLinkOriginal['link_text'] stays what it was before. Essentially, nothing gets updated.
2nd Log: the dirty lists all of the differences correctly; however, it also lists stuff that wasn't changed and basically "dirties" the entire object. Instead of just updating link_text (the only field that actually needed updating), it tries to update every column and lists every column despite some columns being (consistently) NULL at all times.
3rd Log: Shows the correct values that need to be updated which changes from query to query as it should (ie. if link_text does not need to be updated it, it's not) but it has the same problem as the 1st log, in that the 'link_text' shows up as needed to be changed even though it was supposed to be updated the last time around. As opposed to the 2nd log, the columns that don't need updating don't show up.
The SQL: The Update query tries to update EVERY FIELD in the table instead of just the changed fields. It does the query correctly UPDATE "links" SET "link_text" = 'textforlinkg', "link_title" = 'Title for link', etc. WHERE "id" = '2530032904823'; but it lists the columns that don't need to be changed and tries to update them.
RESULT? None. I ran the script several times over and despite the update query being run (according to Laravel), nothing gets updated.
Also, I wanted to mention this. When I was on Laravel 2.3.4 instead of 2.3.5, only the changed columns would update, not all of them. Strange change.