At the Forge - Shoehorning Data into a Database
Not all data fits cleanly into two-dimensional tables. When this occurs, you can try to shoehorn your data into an inappropriate container. Or, you can try to use the help that is built in to one or more levels of your software stack. If you use PostgreSQL, inheritance can be really useful. If you use Rails, you can take advantage of polymorphic associations, allowing you to treat two or more models with a common API as similar. This isn't the sort of thing you'll do each day, but it's a useful skill to have on hand for cases when you need to take unusual data.
To learn how PostgreSQL allows for inheritance, read the on-line manual at www.postgresql.org/docs/8.3/static/ddl-inherit.html.
Rails Cookbook, by Rob Orsini, and published by O'Reilly, has some good information about polymorhphic associations.
The Rails Wiki has some good examples and descriptions of polymorhphic associations at wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations.
Reuven M. Lerner, a longtime Web/database developer and consultant, is a PhD candidate in learning sciences at Northwestern University, studying on-line learning communities. He recently returned (with his wife and three children) to their home in Modi'in, Israel, after four years in the Chicago area.
- Reply to comment | Linux Journal
6 hours 3 min ago
20 hours 30 min ago
- Why choose a Flash based product?
21 hours 7 min ago
1 day 9 hours ago
2 days 1 hour ago
- Thanks for clearing that up.
2 days 6 hours ago
- Nice coding on the cake. I
2 days 18 hours ago
- Baker's identity
2 days 23 hours ago
- Uber jealous
3 days 4 hours ago
- Reality is disapointing
3 days 14 hours ago