How to reference a database column in rails active record interface -


really confused.

i've been reading through rails guide , there seem difference ways reference column in rails. it's string eg

client.select("viewable_by, locked") 

and colon @ beginning

client.select(:name).uniq 

when decide use? these interchangeable?

if string, injected sql statement, allows advanced sql-y stuff,

select("count(name) name_count, nvl(price, 'n/a')") 

(this example, mashing stuff together)

if want select columns, use symbols or array of symbols, like

client.select(:viewable_by, :locked) 

so in short: yes interchangeable, string not parsed, injected sql statement, allows more advanced stuff if needed.


Comments