1

I have a serialized array in the value field of key_value, to which I constantly what to append values. An easy way to do this is to get the array, append the new value, and reinsert it. However, with a large enough array it's quite inefficient and in theory it can be done on an SQL level.

What's the correct way to do this in Drupal 8? Is there a way that does not involve getting and then setting the array?

2
  • Why put the values in a serialized array? Store the values in the database directly, in your own table.
    – 4uk4
    Commented Mar 11, 2018 at 13:35
  • Put otherwise, you can't. You need to get the whole string, unserialize it, extend it in PHP and then serialize and save it again. There are many alternatives, custom table, your own collection where you add new entries and so on. provide more details
    – Berdir
    Commented Mar 11, 2018 at 15:09

1 Answer 1

-1

The best way to go about doing this is by using config API. If somehow this option is not suitable for your use case. You can also use the DB API to update the desired congratulation table records. In both cases, you will need to unserialize the blob then change the data and serialize it back before inserting it into the database.

https://www.drupal.org/docs/8/api/configuration-api/configuration-api-overview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.