Hi, I''ve a model with the following method: def self.run(sql) return connection.select_all(sql) end so, the value returned is an array of hashes... the problen is that the sql command: "select name, id from table" and select id,name from table" returns the columns in the same order (name, id). And in my view, I need to keep the order of the SQL command. (Don''t ask why I''m doing raw SQL.... it''s a long story). :-) Thanks everybody.
Hashes in Ruby don''t have any order. There is an OrderedHash class in Rails which may be worth looking at. It may be possible to maintain the order if you go right down to the database specific connection object, below the AR connection layer. There may be a choice of hash or array based results. -Jonathan. On 6/21/06, Matias <matiassurdi@gmail.com> wrote:> Hi, I''ve a model with the following method: > > def self.run(sql) > return connection.select_all(sql) > end > > so, the value returned is an array of hashes... the problen is that the sql > command: > > "select name, id from table" > > and > > select id,name from table" > > returns the columns in the same order (name, id). > > And in my view, I need to keep the order of the SQL command. > > (Don''t ask why I''m doing raw SQL.... it''s a long story). :-) > > Thanks everybody. > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks, That''s just what I ended doing, by using the ruby-mysql result set I could finally do what I wanted. Matias.> Hashes in Ruby don''t have any order. There is an OrderedHash class in > Rails which may be worth looking at. > > It may be possible to maintain the order if you go right down to the > database specific connection object, below the AR connection layer. > There may be a choice of hash or array based results. > > -Jonathan. > > On 6/21/06, Matias <matiassurdi@gmail.com> > wrote: >> Hi, I''ve a model with the following method: >> >> def self.run(sql) >> return connection.select_all(sql) >> end >> >> so, the value returned is an array of hashes... the problen is that the >> sql command: >> >> "select name, id from table" >> >> and >> >> select id,name from table" >> >> returns the columns in the same order (name, id). >> >> And in my view, I need to keep the order of the SQL command. >> >> (Don''t ask why I''m doing raw SQL.... it''s a long story). :-) >> >> Thanks everybody. >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >>