Hi all,
ror has been much fun the past few weeks. I''m looking forward to
using it where I can in the future.
AR is great, but now my application is at a level where I am ready
to think about optimizations. The database is the first spot to start,
as it is the most hellish.
How about this: if you dont send an argument to find_all, I''ll give
you back some join data. If you only ask for a where clause, I''ll pass
that along and send you join data.
class Claim < ActiveRecord::Base
#appripriate has_many and belongs_to entries....
def Claim.find_all (*args)
sql = "SELECT claim.*, client.title as client_title, division.title
as division_title, project.title as project_title "
sql << "FROM claim "
sql << "JOIN client on (claim.client_id = client.id) "
sql << "JOIN division on (claim.division_id = division.id) "
sql << "JOIN project on (claim.project_id = project.id) "
sql << "WHERE #{args[0]} " if args[0]
sql << "ORDER BY claim.claimant_name ASC"
return find_by_sql(sql) if args.nitems == args.length #if you sent
nothing
return find_by_sql(sql) if args[0] #if you sent a conditional
super *args #if we''re confused
end
end
So what are the central failing points of this? If I had a way to
remap claim.client_title to claim.client.title I would also be able to
use the same variable names across my application, and use speedy joins
in 90% of the cases. Also as a thought is doing the reverse, making
claim.client.title show up as claim.client_title. I''m happy with this
how it is now, I''m just trying to think of ways It can/will bit me in
the ass, and ways to make it more transparent as an optimization.
Thanks all,
-Matthew Beale