Forum: IronRuby Ordered active record attributes hash

Posted by Eduardo Blumenfeld (eblumenfeld)
on 2010-07-31 00:26
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 by Eduardo Blumenfeld (eblumenfeld)
on 2010-07-31 21:32
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?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.