Forum: Ruby on Rails How to run direct DML (insert or update)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
753528fbc8b89d5f3bbcd5558c36d168?d=identicon&s=25 Glenn Cadman (glenn)
on 2006-05-19 07:33
I want when the user clicks on a button on the browser
"Perform monthly billing run"  the controller to lanch a sql DML
statment to be called (in the model?) than runs something like

"insert into billing (item, qnt, total_cost, billing_run_timestamp
 select item, qnt, item*cost as total_cost, timestamp
 from services
 where service_end_date is null"

How can I run a DML (insert, update, delete) direct sql statement ?
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Richard Williams (Guest)
on 2006-05-19 15:30
(Received via mailing list)
On Friday, May 19, 2006, at 7:33 AM, Glenn Cadman wrote:
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


Item.connection.execute("select count(*) from items")

or generally:

<Model>.connection.execute(<SQL>)
753528fbc8b89d5f3bbcd5558c36d168?d=identicon&s=25 Glenn Cadman (glenn)
on 2006-05-22 03:40
Thanks Richard it works perfectly
This topic is locked and can not be replied to.