Home In Rails console, how do I show all sql selected attributes?
Reply: 0

In Rails console, how do I show all sql selected attributes?

user824
1#
user824 Published in May 20, 2018, 10:00 am

This has been a confusing issue for me for years, and I've never asked about it. Why is it that I can't see name in the following console output even though I clearly selected it?

If I assign that output to a variable and say relation.first.name I will see the name, but I can't get the name to show in console. Also, if I convert the ActiveRecord relation to an array, I see a similar problem:

2.3.5 :070 > a.first
#<ActsAsTaggableOn::Tagging:0x00007ff9f3779aa8> {
    :id => 139
}
2.3.5 :071 > a.first.name
"phones"

Is there a better way to deal with this? For the moment, all I can figure is to map this to make it visible, which make writing queries a pain:

a.map{|tag| [tag.id, tag.name]}

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316833 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO