Frederick Cheung wrote: > On Oct 18, 7:34�am, Greg Willits <[email protected]> > wrote: >> Rails 2.3.2, MySQL 5.0.67, mysql-ruby 2.7, ruby 1.8.6 >> >> I am using AR.base.connection.execute to handle a particular case where >> I want to avoid all AR callbacks and optimistic versioning. >> >> When the code is run, the query statement, an update, makes no changes >> to the intended record. >> > > Does your code look like this : > > m = Model.find(...) > AR::Base.connection.execute(...) > m.reload > > ? > > Does it work if you paste it into script/console ? > If so I'd guess that Rails' query cache is the problem. If so, > changing AR::Base.connection.execute to AR::Base.connection.update > would fix this
Thanks, I just needed some kind of comment to inspire me to try something different, and it worked. Your comments gave me an idea to try one thing. That one thing caused the code to finally spit out an error. The error is what I suspected, but had no way to prove, but now realize is obvious. Why the error shows up after this change makes no sense to me, but nevertheless I know what's wrong now. The model in question requires a specific named connection in order to use a specific database (multi-db application). Of course, using AR::Base.connection wasn't using the correct db. However, this code is in a general-purpose acts_as_pessimistic plugin I've written (which does it better than the built-in way IMO), and I don't see any way it can know about the multi-db goings on, so I need to solve the task a different way. I need to avoid validation, so I can do that with save(false), and I need to avoid changing lock_version if it exists. You gave me and idea for the latter last year, so I'll give that a go here too. -- gw -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

