Forum: Ruby on Rails 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.
B5a793b425c4db1f45c3cdfec5697047?d=identicon&s=25 scott (Guest)
on 2006-05-31 13:13
Hi

I have the following code, which makes use of an sql statment to get the
results required.

However this just doesnt seem right for rails, as ive managed to develop
the whole  project without using any other pure sql.

Is there a cleaner way of doing this, but gaining the same results.

thanks
scott

    #sql to find all invoices
    pSql = "SELECT DISTINCT invoices.id, invoices.invoice_number,
invoices.approve_date, invoices.sent_date, invoices.paid_date
            FROM projects, payments, invoices
            WHERE projects.id = payments.project_id
            AND payments.invoice_id = invoices.id
            AND projects.id = " + params[:id] + "
            ORDER BY invoices.id"

    @invoices = Invoice.find_by_sql(pSql);
This topic is locked and can not be replied to.