Sent from my iPhone
On Nov 13, 2010, at 1:44 PM, Bryan Larsen <[email protected]> wrote: > First, it's standard practice to use [polymorphic > tags](http://cookbook.hobocentral.net/manual/dryml-guide#polymorphic_tags) > rather than defining a render method on your model object. OTOH, sometimes > it is reasonable to define a method on the model object: the "name" method is > a reasonable example here. The name() method has become my friend in recent weeks. > 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. > > 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. > > On 10-11-12 02:48 PM, Peter Booth wrote: >> I'm wondering if there's a Right Way to do the following in Hobo/Rails? >> >> I'm working on an application that will list (aggregate) a collection of >> dissimilar objects that are rendered differently depending on their type. >> Specifically the objects are product reviews, where some might have one or >> more numeric scores, comments, stars. Some objects might summarize reviews >> (average 4.56 of 7 reviews). The appropriate formatting will depend on the >> review source. >> >> So I first thought product has_many reviews, where a review is an object >> that has a render method, but actually there would be many review types, >> with different implementations of render(). >> >> I'm wondering whether each of these objects should in fact be different hobo >> models, or if there is any reason to hide this? >> >> I hope this explanation makes sense >> >> Sent from my iPhone >> > > -- > 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. > -- 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.
