From: David Vallner Date: 2006-10-20T19:10:29+09:00 Subject: Re: Storing a Hash in a database table using YAML--anything better? --------------enig704D5B2FE891C78364F35FC6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable J. B. Rainsberger wrote: > I want to store a hash as a single row in a database table. I'm > currently storing each name/value pair as a row with a reference back t= o > the "parent" row, but that seems unnecessarily complex. I want to know > whether you have any better suggestions than what I plan to try to do. >=20 Disclaimer: A lot of the following will be database access performance related. In personal code with low usage, those can be safely ignored, but for a self-education project, I prefer following good practices to learn them even if they seem clunky. What's the structure of the hash? If it could be replaced by a data structure, I'd do so and keep this approach (it IS the correct one from the relational data modelling point of view), unless you're sure the hash is an atomic value object by design. I'd especially not use the serialization approach if you need to filter your data according to the contents of that hash - the "draw all records from the DB and filter them in Ruby" approach makes baby DBA Jesus cry and is a good candidate for becoming a bottleneck. I'd also not use the serialization approach if it's binary serialisation - if you ever had to access the database from anything except Rails (e.g. Crystal Reports), you're screwed. David Vallner --------------enig704D5B2FE891C78364F35FC6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFOKCNy6MhrS8astoRAvnRAJ9XWxWNifFw2JBYfAI3xFb9lJ71qgCfWkd9 x0bBEMZ9UhagLEweL+9nOFY= =bKTY -----END PGP SIGNATURE----- --------------enig704D5B2FE891C78364F35FC6--