On Apr 20, 3:19 pm, Patrick Clas <[email protected]> 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... >
For something like this, if you want to do it in a single query then you'll probably just have to write some sql to do it, perhaps something like update users inner join game_collections on games_collections.user_id = users.id set points = points + 2 where game_id = 23 and percentComplete = 100 if a user had multiple rows in game_collections then this might do funny stuff. Make sure you think about the edge cases and test for them! Fred > 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. > -- > Posted viahttp://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 > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- 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.

