You can only access what you retrieve. Given Rails dynamic nature, if
you do a
model = Model.find_by_sql(''select attr from models where
id=1'')
your model will only contain attr and trying something else will give an
"undefined method".
You could even do a
model = Model.find_by_sql(''select attr as blah from models where
id=1'')
and do model.blah. Not recommanded though.
Ryan Wood wrote:
>I assume if you have a Post class, that Post.find_by_sql should return
>an array of Post objects.
>
>But, how does what you return from the sql statement affect the results?
>
>For instance, does it matter if you say "select * from posts"
versus
>"select id from posts" versus something non-sensical such as
"select
>updated_at from categories"?
>
>I''ve seen cetain instances where someone returns a db field in the
sql
>that does not exist in the model. How does that work? What''s the
>relationship between the sql executed and the return object(s).
>
>Thanks,
>
>Ryan
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>