Eduardo Blumenfeld
2010-Jul-30 22:26 UTC
[Ironruby-core] Ordered active record attributes hash
Hi All: I''m trying to traverse the active record attributes hash in the order it was created. ------------------ a = Table.find_by_sql("select * from sometable") a.each { |row| puts row.to_yaml # prints the the attributes in the order coming from the select statement # which is exactly how I would like to process the columns puts row.attributes.to_yaml # shows the attributes in sorted order... } ------------------ Is that a problem with activerecord? how I could solve the issue? -- Posted via http://www.ruby-forum.com/.
Eduardo Blumenfeld
2010-Jul-31 19:32 UTC
[Ironruby-core] Ordered active record attributes hash
Hi all, I found the solution for this puzzle: Active record, when you call the procedure attributes, it sorts the attributes by key, so, by working in the following way, that works correctly: row.instance_variable_get(:@attributes).to_yaml instead of row.attributes.to_yaml Thank you anyways Eduardo Eduardo Blumenfeld wrote:> Hi All: > > I''m trying to traverse the active record attributes hash in the order it > was created. > ------------------ > a = Table.find_by_sql("select * from sometable") > > a.each { |row| puts row.to_yaml > # prints the the attributes in the order coming from the select > statement > # which is exactly how I would like to process the columns > puts row.attributes.to_yaml > # shows the attributes in sorted order... > } > > ------------------ > Is that a problem with activerecord? > > how I could solve the issue?-- Posted via http://www.ruby-forum.com/.