Array is filled from query using arbitrary SQL statement
@myarray = myObject.find_by_sql(sql)
SQL is designed in such way that each myarray
item has same fields as myObject
Model, e.g.
\#{myObject value: 100, day: 2013-06-15}
Ideally, I would like to have array of myObjects
- Filled with data from Array;
- Accessible for html;
- Not saved to the database.
Is it at all possible?
From docs for ActiveRecord::Querying#find_by_sql
:
Executes a custom SQL query against your database and returns all the results. The results will be returned as an array with columns requested encapsulated as attributes of the model you call this method from. If you call Product.find_by_sql then the results will be returned in a Product object with the attributes you specified in the SQL query.
So I don't really understand your question. AR will try to map fields returned from query to object fields.
It is accessible in views if you assign it to object variable.
Records never got saved unless you execute one of the methods that perform save.
EDIT:
Remember that AR will not be able to map resultset to records unless you return id column.