Forum: Ruby on Rails RE: find by sql

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.
Bharat A. (Guest)
on 2006-05-31 16:12
(Received via mailing list)
>
>     @invoices = Invoice.find_by_sql(pSql);


Try @invoices = Invoice.find(:all, :select => "Distinct  invoices.id,
invoices.invoice_number, invoices.approve_date,invoices.sent_date,
invoices.paid_date",
				       : join => " ,projects, payments",

				       :Conditions =>["projects.id =
payments.project_id AND payments.invoice_id = invoices.id AND
projects.id = ?",params[:id]])

Although I have not tried it, it should work. If not take a look at the
log file to see what is the sql being generated and customize the above
statement accordingly.

Bharat
This topic is locked and can not be replied to.