I've never done it, but my first idea would be to wrap up the master-detail "transformation" in the master objects CRUD methods and use the "has_many :children" and "belongs_to :parent" functionality.
<br><br>One concern is that you lose a lot of the power of using indexes to optimize your queries when implementing this type of database model.&nbsp; It may not matter in your case...<br><br><div><span class="gmail_quote">On 11/9/06, 
<b class="gmail_sendername">Tim Pease</b> &lt;<a href="mailto:tim.pease@gmail.com">tim.pease@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This is a little long, but please bear with the explanation.<br><br>I want to be able to setup a database table that can hold different<br>kinds of &quot;stuff&quot; where each type of &quot;stuff&quot; can have vastly different
<br>contents (or attributes). For example, one type of stuff would be<br>information about a person -- name, age, address, hair color, etc.<br>Another type of stuff would be a book -- title, author, ISBN.<br><br>I would like to store all these things in one table so that I can have
<br>a join table linking a user to their &quot;stuff&quot;. The join table would<br>have user specific attributes about the stuff (description, tags,<br>etc).&nbsp;&nbsp;The &quot;stuff&quot; table would only have one copy of each &quot;stuff&quot;
<br>item.<br><br>Some SQL ...<br><br>CREATE TABLE stuff (<br>&nbsp;&nbsp;&nbsp;&nbsp;id&nbsp;&nbsp;INT&nbsp;&nbsp;NOT NULL&nbsp;&nbsp;AUTO_INCREMENT PRIMARY KEY,<br>&nbsp;&nbsp;&nbsp;&nbsp;type VARCHAR(50) NOT NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;name TEXT&nbsp;&nbsp;NOT NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;description&nbsp;&nbsp;TEXT&nbsp;&nbsp;NULL<br>);<br><br>CREATE TABLE stuff_attributes (
<br>&nbsp;&nbsp;&nbsp;&nbsp;stuff_id&nbsp;&nbsp;INT NOT NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;name VARCHAR(45) NOT NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;value TEXT NOT NULL<br>);<br><br><br>The idea here is that each &quot;type&quot; of stuff gets stored in the stuff<br>table with the type attribute set to what it is ('person' or 'book').
<br>The attributes about that stuff are then stored in the<br>stuff_attributes table, with each attribute being a separate entry<br>with the &quot;name&quot; of the attribute and the &quot;value&quot; for the attribute.<br>
<br>For a book, then, there would a single entry in the stuff table<br>describing the thing's type as a &quot;book&quot;, the book's name and a<br>description.&nbsp;&nbsp;The stuff_attributes table would have three entries --<br>the title attribute and its value, the author attribute and its value,
<br>and the ISBN attribute and its value.<br><br>Obviously there will need to be an SQL join when doing any query to<br>get information about particular stuff.<br><br>Does ActiveRecord make this dead simple?&nbsp;&nbsp;Or will I end up rewriting
<br>most of the ActiveRecord methods to make this kind of table schema<br>work?<br><br>More general, is there a better way of doing this kind of generic data<br>about stuff in ActiveRecord?<br><br>Any helpful pointers are appreciated. Actual working Rails code with
<br>attached database schema will get you a free beer on Wednesday night<br>;)<br><br>Blessings,<br>TwP<br>_______________________________________________<br>Bdrg-members mailing list<br><a href="mailto:Bdrg-members@rubyforge.org">
Bdrg-members@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/bdrg-members">http://rubyforge.org/mailman/listinfo/bdrg-members</a><br></blockquote></div><br>