Hi,
I am trying my hands on RoR for a dummy project and I use Mysql as my
database. For data manipulation and querying purpose, should I write
ruby code directly in active record or write a stored procedure and
invoke a call through active record?
I understand there are many advantages of stored procedures:
They can help enforce data security.
2.Amount of information sent over the N/W is less
No compilation step is required to execute code
Once the procedure is present in the shared pool, retrival from
disk is not required everytime different users call the procedure i.e.
reduction in disk I/O
Once the procedure is present in the shared pool, retrival from
disk is not required everytime different users call the procedure i.e.
reduction in disk I/O
With ActiveRecord, you can made all SQL querie that you want with
several method of _sql or with a connection by driver. But it’s not
needed. ActiveRecord made several method to avoid this SQL querie in
your Ruby Code.
So Avoid made SQL except for perform, but it’s not advisor by default.
We call stored procs when we have to query a particularly unfriendly
part of our database, but for the most part, we let ActiveRecord
handle creating all the SQL for us as Cyril said. Unless you have some
big, nasty ultra-normalized parts of your database, you shouldn’t need
to write any SQL statements at all, just let your relationships in
ActiveRecord work their magic.