I need to apply “find” instead of find_by_sql. Kindly suggest me. Because, params[gm] is not working with find_by_sql. Kindly justify whether my code below is in correct syntax…
find_by_sql(“SELECT column1 FROM table WHERE column2 = ‘params[gm]’ ORDER BY column1”)
I need to apply “find” instead of find_by_sql. Kindly suggest me. Because, params[gm] is not working with find_by_sql. Kindly justify whether my code below is in correct syntax…
find_by_sql(“SELECT column1 FROM table WHERE column2 = ‘params[gm]’ ORDER BY column1”)
–
With Regards
Palani Kannan. K
Office: +49-531-2616-226
Mobile: +4917647098166
Well, depending on your version of ActiveRecord (and assuming that your model is called Model)
But that will give you anemic and readonly instances of Model because they don’t have their id column.
If you want fully formed Model instances, don’t specify the select part.
If you just want the values of column1, you could do something like:
Model.connection.select_values(Model.send(:sanitize_sql, [“SELECT DISTINCT column1 FROM #{Model.table_name} WHERE column2 = ? ORDER BY column1”, params[gm]))
But that’s obviously a bit ugly.
Perhaps you should ask with REAL names from your application so that the answers can be made more naturally.