Permalink
Browse files

Added a method for generating a PK for the view.

  • Loading branch information...
barendt committed Nov 28, 2012
1 parent b33b0ee commit a6c29f7e2c05fcc5bb238618513518c642cf1077
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb
@@ -29,6 +29,15 @@ def create_view(name, select_query, options={})
create_sql << " WITH #{options[:check_option]} CHECK OPTION" if options[:check_option]
execute create_sql
end
+
+ if options[:primary_key]
+ create_primary_key_for_view name, options[:primary_key]
+ end
+ end
+
+ def create_primary_key_for_view(name, primary_key)
+ sql = "ALTER VIEW #{quote_table_name(name)} ADD CONSTRAINT #{quote_table_name(name)}_pk PRIMARY KEY(#{primary_key}) DISABLE"
+ execute sql
end
# Also creates a view, with the specific purpose of remapping column names

0 comments on commit a6c29f7

Please sign in to comment.