On 9 May 2010 10:02, Fearless Fool <li...@ruby-forum.com> wrote:
> If an active record is returned as a result of a find_by_sql() query,
> what must be true in order for it to be save-able?  Here's an example of
> it not working:

The clue is in the question...

You're not selecting an "active record" (record), you're selecting a
string value - your query doesn't return a record from a table, it
just returns a string from SQL. AR has no idea what to update, so the
SQL generated when you save will be along the lines of "Update blurgs
set name = 'tac' where id = ''". That will return "true" as it doesn't
"fail" - there are just no records to update.


Coming back to my first thought when I read your code: WTF? What are
you *trying* to do?! Why are you hoping to achieve with that
find_by_sql? Are you trying to find the first record you created? If
so, you need to learn some SQL:

b = Blurg.find_by_sql("SELECT * from blurgs where name = 'tic'")

If that's not what you're trying to do, please explain.

-- 
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 rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to