On Nov 13, 2010, at 2:48 PM, Peter Booth wrote: > >> I see a couple of options: >> >> 1) STI, aka Single Table Inheritance. This means that a single database >> table holds all the attributes for all of the different types of objects, >> and one column is used to hold the "type". This generally just means that >> some columns are unused in some objects. See >> http://cookbook.hobocentral.net/recipes/23-using-single-table-inheritance-sti-models >> for a recipe on how to use STI. (Note that there may be an issue using STI >> with Hobo on Ruby 1.9.2 -- Ruby 1.8.7 works.) > > I worked on an app that used STI for a model. This was a table whose size was > proportional to 100x number of registered users. So as the userbase grew we > had millions of rows that all include OneVeryLongCamelCaseClass and > AnotherVeryLongCamelCasedClass. I couldn't see why ActiveRevord didn't use a > numeric key instead of the classname. >
The problem I could imagine with a numeric key is that it still needs to be mapped consistently to the correct class name, even in the face of adding/removing classes from the possible choices. The AR method has the advantage that a record's type can be readily determined when it's read from the DB, without reference to any other tables or configuration. >> >> 2) rather than "has_many reviews", you can just use: >> >> has_many :amazon_reviews >> has_many :yelp_reviews >> def reviews >> amazon_reviews+yelp_reviews >> end >> >> then <collection:reviews> will automagically do the right thing and >> correctly display the correct card for each review. > > This looks like a winner for my use case. Thank you very much, Hobo is > increasing my enthusiasm for coding. One note on this: this method will load *all* the objects in both associations, and won't work with pagination. In your application, that may not be a problem - but it's worth being aware of. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
