Ruby on Rails Wednesday, October 21, 2015

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAAJ2eVpLcG75VfkRtN6z8-pwNhB0_i4%2BBA%2BUgtKfx%2BV8F900GQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment