Hi, This is my current code *@descriptions = TableName.find(:first, :conditions=> ["table_id = ?", table_name.table_id], :order => ''author_year'')* *author_year* column contains data of kannan 1845 kohlun 1976 palani 1956 Using above code, it gives result with order of author_year based on author names. I need to order the query ascendingly based on the year which presents in author_year. and I wish to print the oldest data based on the year not ordered by author name. Kindly give me some suggestion on this issue. -- With Regards, Palani Kannan. K, -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Refactor the DB to have those fields available separately. You have two distinct pieces of data munged together in one field. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Oct-25 14:06 UTC
Re: [Rails] Re: pattern findings using “find” in Rails
Hi Ar Chron, Thank you for reply On 25 October 2010 14:55, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Refactor the DB to have those fields available separately. You have two > distinct pieces of data munged together in one field. >I shouldn''t edit or modify the data in database. The data has not munged. The default data field is created with two pieces. In general author referencing, the data will be included with year and author name. Author name and year are the two pieces in author_year column. Kindly tell me if functions available to sort SQL query output with second piece only as sorting element.> >-- With Regards, Palani Kannan. K, -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-25 15:35 UTC
[Rails] Re: Re: pattern findings using “find” in Rails
PalaniKannan K wrote in post #956892:> Hi Ar Chron, > > Thank you for reply > > On 25 October 2010 14:55, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Refactor the DB to have those fields available separately. You have two >> distinct pieces of data munged together in one field. >> > > I shouldn''t edit or modify the data in database.No, but you should change the schema.> The data has not > munged.Yes it is.> The default data field is created with two pieces.Right. That''s a bad design. You should change it. One field should contain only one piece of data. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 25, 3:06 pm, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 25 October 2010 14:55, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > I shouldn''t edit or modify the data in database. The data has not munged. > The default data field is created with two pieces. In general author > referencing, the data will be included with year and author name. Author > name and year are the two pieces in author_year column. Kindly tell me if > functions available to sort SQL query output with second piece only as > sorting element. >If you really want to ignore what others have said the :order options takes an sql fragment. SQL has some string manipulation functions so you can probably come up with a way of extracting the year from that column, but such a query wouldn''t be able to use any indexes to help with the ordering so you might end up with something slow as well as something yucky. Fred> > > -- > With Regards, > > Palani Kannan. K,-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Oct-26 15:04 UTC
Re: [Rails] Re: pattern findings using “find” in Rails
Hi Frederick, 2010/10/25 Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > If you really want to ignore what others have said the :order options > takes an sql fragment. SQL has some string manipulation functions so > you can probably come up with a way of extracting the year from that > column, but such a query wouldn''t be able to use any indexes to help > with the ordering so you might end up with something slow as well as > something yucky. >I tried def author_yr "#{self.author_year.last(4)}" end. But it shows "Undefined local variable or method ''author_yr''" when i use author_yr in find by ":order => ["author_year like = ?", author_yr]". Please suggest me some idea in ordering.> Fred > > >-- With Regards, Palani Kannan. K, -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K wrote in post #957235:> > I tried > def author_yr > "#{self.author_year.last(4)}" > end. > > But it shows "Undefined local variable or method ''author_yr''" > > when i use author_yr in find by > > ":order => ["author_year like = ?", author_yr]". Please suggest me some > idea > in ordering.> Palani Kannan. K,Impossible. You''re defining author_yr in a ruby model, but expecting the DATABASE to know what that is. Doesn''t work that way. As Fred mentioned, you need to use a database function that looks at the "author_year" field (the last 4 characters) to order upon. Look in the manuals for whatever DB engine you''re using for string functions. That''s what goes in the :order => [] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-26 16:54 UTC
[Rails] Re: Re: pattern findings using “find” in Rails
Ar Chron wrote in post #957266:> PalaniKannan K wrote in post #957235: >> >> I tried >> def author_yr >> "#{self.author_year.last(4)}" >> end. >> >> But it shows "Undefined local variable or method ''author_yr''" >> >> when i use author_yr in find by >> >> ":order => ["author_year like = ?", author_yr]". Please suggest me some >> idea >> in ordering. > >> Palani Kannan. K, > > Impossible. > > You''re defining author_yr in a ruby model, but expecting the DATABASE to > know what that is. Doesn''t work that way.Where is the OP doing that? What he is doing instead that is wrong is using a Rails-style conditions array in an ORDER BY clause. *That* doesn''t work that way. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
PalaniKannan K
2010-Oct-26 17:24 UTC
Re: [Rails] Re: Re: pattern findings using “find” in Rails
> > > > Palani Kannan. K, > > Impossible. > > You''re defining author_yr in a ruby model, but expecting the DATABASE to > know what that is. Doesn''t work that way. > > As Fred mentioned, you need to use a database function that looks at the > "author_year" field (the last 4 characters) to order upon. >I got your point. I will look for last 4 character to order up in database function. thank you for suggestion.> > Look in the manuals for whatever DB engine you''re using for string > functions. That''s what goes in the :order => [] > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards, Palani Kannan. K, Doctoral Researcher, Microbiology Department, German Collection Center for Microorganisms and Cell Cultures, Helmholtz-HZI Infectious diseases Research Campus, 38124, Braunschweig, Germany. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.