What is the complexity of Model.columns?

16 views
Skip to first unread message

Sadaf Noor

unread,
Oct 22, 2015, 12:38:05 AM10/22/15
to rubyonra...@googlegroups.com

What is the complexity of active record Model.columns or Model.column_names operation on rails?

Basically I have an option of either hard coding it like that:

do_something(:column_name1)
do_something(:column_name2)
do_something(:column_name3)

or I can do that as following:

columns = Model.columns
columns.each do |c|
   do_something(c.name)
end

I want to use the second one, because I have to do that in couple of models and if I choose the second option it saves me time and lines of code. But I am thinking if I had to face any time penalty at run time or not?

Also posted on stackoverflow: http://stackoverflow.com/questions/33273311/what-is-the-complexity-of-model-columns-or-model-column-names-on-rails



--
 Md. Sadaf Noor (@sadaf2605)
 www.sadafnoor.com
Reply all
Reply to author
Forward
0 new messages