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.
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.
Are you absolutely sure you cannot do it using normal rails
relationships and avoid find_by_sql?
I prefer to have a model for my results, I think it’ll be enhanced
with more attibutes when I progress in the development.
Is there not an issue then that there will be multiple ways of
accessing overlapping attributes? I suppose if it is read only that
may be less of an issue. You might end up having to replicate
business logic though.
from
users u, users ug, members m, projects p,
issues i, time_entries t,
issue_categories ic, groups_users g, category_attrs att
left join enumerations ptype on ptype.id =
att.project_type_id
left join enumerations rtype on rtype.id =
att.request_type_id
I prefer to have a model for my results, I think it’ll be enhanced
with more attibutes when I progress in the development.
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.
Your accessors are trying to read from instance variables, but
activerecord attributes aren’t stored in individual instance
variables. Your initialize method doesn’t have the signature expected
either. I’d try removing both