Prev: Ruby Webbrowser
Next: Mocking a method with a block
From: Austin Fagan on 31 Jul 2010 09:13 Hi, I am writing a script that queries a database for records with either the value '333' or '444' in a field called pin_id in a table called pop. Currently I have created a model called GoodPop using set_table_name :pop I have overrided the first, last and all methods to return only those records with a pin_id of either '333' or '444'. This doesnt feel right. I was thinking of using the inheritance_column to change the type to the pin_id column but then I would need to call the model name to either 333 or 444- is this right? Can anyone offer any suggestions? Thanks MM -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 1 Aug 2010 07:28 Austin Fagan wrote:0 > I am writing a script that queries a database for records with either > the value '333' or '444' in a field called pin_id in a table called pop. > Currently I have created a model called GoodPop using set_table_name > :pop > I have overrided the first, last and all methods to return only those > records with a pin_id of either '333' or '444'. Don't Do That. Look up the AR documentation for named scopes and anonymous scopes. -- Posted via http://www.ruby-forum.com/.
From: Austin Fagan on 1 Aug 2010 11:01 Brian Candler wrote: > Austin Fagan wrote:0 >> I am writing a script that queries a database for records with either >> the value '333' or '444' in a field called pin_id in a table called pop. >> Currently I have created a model called GoodPop using set_table_name >> :pop >> I have overrided the first, last and all methods to return only those >> records with a pin_id of either '333' or '444'. > > Don't Do That. > > Look up the AR documentation for named scopes and anonymous scopes. Thanks Brian, using named_scopes!! -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: Ruby Webbrowser Next: Mocking a method with a block |