Thanks Pratik, I just confirmed that solution works but it doesn't answer my question about update_all not using custom filters. Is that a bug or an expected behaviour? (I understand that technically unless you do a single query at a time, filters aren't used)
Thanks, -Matt On Sep 7, 1:20 pm, Pratik <[EMAIL PROTECTED]> wrote: > Oops my bad. > > 1. Yeah, it should be map(&:id). > > 2. Yeah, you won't need Photo.find(:all, :conditions => ["id IN ?", > @photo_ids]).map(&:id) if you have ids already, I was just making it > generic case where condition could be anything. > > 3. No.That will create ids.length+1 number of queries. And yes, it > will use your filters. > > On 9/7/07, Matt Aimonetti <[EMAIL PROTECTED]> wrote: > > > > > > > > However, note that you can do following as of now : > > > > ids = Photo.find(:all, :conditions => ["id IN ?", @photo_ids]).amp(&:id) > > > Photo.update(ids, Hash.new( :title => "Ruby rocks" ) > > > Will that create only 1 SQL query? and will that use my filters? > > > I guess amp(&:id) should read map(&:id) Also, I don't see why you > > would do: > > > > ids = Photo.find(:all, :conditions => ["id IN ?", @photo_ids]).amp(&:id) > > > if we already have the ids. > > > Thanks, > > > -Matt > > > On Sep 7, 12:15 pm, Pratik <[EMAIL PROTECTED]> wrote: > > > I think it'd be nice to have 2 variations of mass update statements. > > > Something like destroy_all and delete_all, where one variation does > > > blind sql query ( like delete_all ) and other shows complete respect > > > for AR ( destroy_all ) > > > > However, note that you can do following as of now : > > > > ids = Photo.find(:all, :conditions => ["id IN ?", @photo_ids]).amp(&:id) > > > Photo.update(ids, Hash.new( :title => "Ruby rocks" ) > > > > On 9/7/07, Matt Aimonetti <[EMAIL PROTECTED]> wrote: > > > > > Hi > > > > > I noticed that if in my code I use the following: > > > > > Photo.update_all("title = 'Ruby rocks' ", "id IN ([EMAIL PROTECTED])") > > > > > All my objects are properly updated but none of the filters/callbacks > > > > are triggered. Is that what's expected? > > > > > I have a before_update filter set on the Photo class and it gets > > > > totally ignored, I guess the only way to solve this issue is to > > > > enumerate through the objects and update them one after the other :( > > > > > Thanks, > > > > > -Matt > > > > -- > > > Cheers! > > > - Pratikhttp://m.onkey.org > > -- > Cheers! > - Pratikhttp://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---