Who Invented Viagra

13th Mar 2009Tech,

Who invented viagra Rails 2.3 includes a new method called default_scope which provides an easy way to set default attributes on a model as it calls on records from the database. Who invented viagra  After playing around with it a bit, who invented viagra I am certain that I’m going to avoid using this method for a few reasons.

Who invented viagra Before I get to that, who invented viagra here’s the syntax:

Who invented viagra You could set a default_scope for any number of conditions, who invented viagra but :order is really the only thing that makes sense to me (red flag number one) because nothing else would have fixed conditions for all database queries.

Who invented viagra With this default_scope in place, who invented viagra we’re going to get an ORDER_BY ‘name’ ASC added to our SQL query when calling Person.all, who invented viagra Person.old, who invented viagra or Person.young. Who invented viagra That’s all well and good until the query gets a little complex–what happens if we specify a different :order in the named scope or in the controller? As you might guess, who invented viagra the default_scope loses out to specifying a different :order in other methods.

Who invented viagra Once your query gets complicated with includes and joins, who invented viagra you’ll find that suddenly the defaulted :order option does not show up in your query and all your people are completely out of order. Who invented viagra  At that point, who invented viagra you’re back to square one needing to manually specify the order in a separate named_scope or in the controller logic.

Who invented viagra The inconsistency here is intolerable, who invented viagra and the code also loses a lot of clarity when it is implemented since it will not work under all circumstances. Who invented viagra  Personally, who invented viagra I like :order options visible in the controller (I put just about everything else in named_scopes) because the code stays clear. Who invented viagra  Just seems to me that it’s better to leave this method out all together.

Average Rating: 4.6 out of 5 based on 292 user reviews.

No Comments Comments Feed

Sorry, the comment form is closed at this time.

The comments are closed.