Tag Archives: sql

Rails 2.1: Aggregate Expressions

Rails 2.1 allows you to perform complex aggregate queries, such as Donation.sum(“amount * 3″). This makes complex calculations a snap! Rails provides functions for calculating the average, count, maximum, minimum, and the sum. Continue reading

Posted in Development | Tagged , , | Comments Off

Find_by_SQL

How can you use the find function if you have complex find criteria–such as searching by fields that don’t exist in the table for your class? Enter the find_by_sql function. It allows you to use arbitrary SQL to find the model records you want–everything from joins and where clauses to having clauses. Rails handles the nitty-gritty work of returning models that have the attributes you selected. Continue reading

Posted in Development | Tagged , , , | Comments Off

Using SQL for complex SELECT/ORDER Criteria

How can you select model objects using a complex SQL criterion (such as ordering by a SUM of values)? The answer is to use the find_by_sql method. You can select complex fields, join tables, and sort on those fields–such as sum fields. Continue reading

Posted in Deployment | Tagged , , | Comments Off