Patrick Clas wrote:
> I'm new to rails and I'm also new to database access so hopefully this
> will be easy to answer, and hopefully I can explain it well enough to be
> understood.
> 
> I've got ActiveRecord objects that all relate to eachother.  User and
> Game have a many to many relationship connected via GameCollection.
> GameCollection also has various attributes such as percentComplete.
> Every user has a certain number of points.  What I am trying to do is
> increment the points for each user that has a game with a certain id and
> percentComplete = 100.  I'm looking to do this by calling
> GameCollection.update or User.update.  I'd be curious how I might be
> able to do it either way.  I just can't seem to figure out the correct
> syntax...
> 
> Any ideas?  Is this doable?  I've previously been doing it manually
> using ruby code, but that is really slow and I want to take advantage of
> the power of mysql updates.

Are you trying to call a SQL UPDATE statement that updates multiple 
records?  If so, then that's not possible with straight ActiveRecord 
AFAIK.  You have three options, roughly in descending order of 
preferability:

* Use the ar-extensions plugin, which does bulk updates.

* Write the SQL yourself (probably not recommended, though you should at 
least understand the syntax)

* Replace ActiveRecord with another ORM like Sequel, which does this 
natively.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
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.

Reply via email to