Lance Ball
2006-Jan-04 19:02 UTC
[Rails] ActiveRecord delete_all With Sanitized Parameters?
Hi there I''m trying to delete a set of active record objects based on certain conditions. I''d like to do something like the following: Context.delete_all("uri IN (?)", uris) But delete_all doesn''t allow multiple arguments. Since I don''t have the IDs for the objects I want to delete, I can''t use delete(id), and have resorted to this, which is significantly slower since it has to instantiate each object, and there are individual SQL statements for each delete. Am I missing something obvious? contexts = Context.find(:all, :include => :terms, :conditions => ["uri IN (?)", uris]) contexts.each do |context| context.destroy end Thanks Lance
Kevin Olbrich
2006-Jan-04 19:23 UTC
[Rails] Re: ActiveRecord delete_all With Sanitized Parameters?
Lance Ball wrote:> Context.delete_all("uri IN (?)", uris)did you try ''Context.delete_all(["uri IN (?)",uris])'' ? -- Posted via http://www.ruby-forum.com/.
Lance Ball
2006-Jan-04 21:00 UTC
[Rails] Re: ActiveRecord delete_all With Sanitized Parameters?
On 1/4/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote:> Lance Ball wrote: > > > Context.delete_all("uri IN (?)", uris) > > did you try ''Context.delete_all(["uri IN (?)",uris])'' ?Well, I guess we all have our moments to be _very_embarrassed_! Thanks - that did the trick. Lance
Lance Ball
2006-Jan-04 21:05 UTC
[Rails] Re: ActiveRecord delete_all With Sanitized Parameters?
Bad form to reply to my own post, but... This does work, however, it has a drawback. Using context.destroy also removes associated rows in my habtm mapping table. Context.delete_all does not. Back to the drawing board... Lance On 1/4/06, Lance Ball <lanceball@gmail.com> wrote:> On 1/4/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote: > > Lance Ball wrote: > > > > > Context.delete_all("uri IN (?)", uris) > > > > did you try ''Context.delete_all(["uri IN (?)",uris])'' ? > > Well, I guess we all have our moments to be _very_embarrassed_! > > Thanks - that did the trick. > > Lance >