diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-23 16:52:06 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-02-23 16:52:06 -0800 |
commit | f10d3be703cada60783c671866dd48194b800002 (patch) | |
tree | 1788a50fe0bb400b528de15a626391d8529f2091 /lib | |
parent | da667908f6c84ecb5dbf7c3e2b9d22ffe4c386a7 (diff) | |
download | rails-f10d3be703cada60783c671866dd48194b800002.tar.gz rails-f10d3be703cada60783c671866dd48194b800002.tar.bz2 rails-f10d3be703cada60783c671866dd48194b800002.zip |
updating functionality
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/relations/update.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/active_relation/relations/update.rb b/lib/active_relation/relations/update.rb new file mode 100644 index 0000000000..d28608fdd5 --- /dev/null +++ b/lib/active_relation/relations/update.rb @@ -0,0 +1,17 @@ +module ActiveRelation + class Update < Compound + attr_reader :assignments + + def initialize(relation, assignments) + @relation, @assignments = relation, assignments + end + + def to_sql(strategy = nil) + [ + "UPDATE #{table_sql} SET", + assignments.inject([]) { |assignments, (attribute, value)| assignments << "#{attribute.to_sql} = #{value.to_sql}" }.join(" "), + ("WHERE #{selects.collect(&:to_sql).join('\n\tAND ')}" unless selects.blank?) + ].join("\n") + end + end +end
\ No newline at end of file |