Serializing block data

Permalink
I am creating a block where users can add unlimited number of text areas. I am thinking of serializing values of all text areas to store them into a single field in the database. Is this the efficient way of storing data or is there a better way?

BlueFractals
 
JohntheFish replied on at Permalink Reply
JohntheFish
There are generally 2 approaches
- an expanding serialized column in your existing block data table (as you have described)
- a secondary table with 1 row per text field that is cross referenced with your block data (which then needs to stay cross-referenced through block versions and changing BID)

Both methods are in use with numerous blocks, so its pretty much up to you and whatever other requirements you have. Maybe one method would achieve faster rendering for your block. Maybe one method is easier to search or filter by. Maybe you need to import and export data.
BlueFractals replied on at Permalink Reply
BlueFractals
Thanks John. The secondary table approach sounds good too. I think it'd be easier if I need to retrieve a specific data, without having to unserialize the entire array. How do I cross reference the second table with the main table? Is there a built-in feature to do that or do I need to explicitly get this done through custom SQL queries inside save() function?
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
I am afraid you need to write some custom SQL. Off the top of my head I think in Save and also a duplicate or copy method. A good example to follow is Jordanlev's free gallery boilerplate code (on Github and I think an early version in the free fancybox gallery).