Hello,

I have custom queries that joins several tables, so I have written a
model class to represent those data. I have extended it from
ActiveRecord::Base in order to be able to use 'find_by_sql'. When I
call 'find_by_sql' it seems to work fine, in the debugger I can see
every record retrieved from DB with their values, but when I try to
access those values through some accessors, they don't give me
anything.

This is my class:

class ProjectsReport < ActiveRecord::Base
 
attr_accessor :total_hours, :group_name, :project_type, :request_type

  def initialize(total_hours, group_name, project_type, request_type)
    @total_hours = total_hours
    @group_name = group_name
    @project_type = project_type
    @request_type = request_type
  end
end

If I use another class that has a table associated to call
find_by_sql, everything works fine, but that isn't a good design.

# This doesn't work because ProjectsReport doesn't have any table on
DB?
    @records =
ProjectsReport.find_by_sql(create_projects_report_query(start_date,
end_date))

# This works but TimeEntry doesn't have anything related with
information retrieved by the query
    @records =
TimeEntry.find_by_sql(create_projects_report_query(start_date,
end_date))

What must I add to ProjectsReport to get it working?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to