Created
February 5, 2010 00:34
-
-
Save klochner/295318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class << Foo | |
def mass_habtm(attr_array) | |
attr_str = attr_array.map{|a| %Q{'#{a}'} }.uniq.join(",") | |
self.connection.execute(%Q{insert into foos_bars (foo_id,bar_id) | |
select distinct foos.id,bars.id from foos,bars | |
where foos.id = #{self.id} | |
and bars.some_attribute in (#{attr_str})}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment