Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
moved the primary key creation inside the if supports_views? block
  • Loading branch information
Walter Davis committed Feb 17, 2015
1 parent 6cab4f5 commit a91d8ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Expand Up @@ -64,10 +64,10 @@ def create_view(name, select_query, options={})
create_sql << "AS #{view_definition.select_query}"
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]
if options[:primary_key]
create_primary_key_for_view name, options[:primary_key]
end
end
end

Expand Down Expand Up @@ -96,10 +96,10 @@ def create_or_replace_view(name, select_query, options={})
create_sql << "AS #{view_definition.select_query}"
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]
if options[:primary_key]
create_primary_key_for_view name, options[:primary_key]
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/test_helper.rb
Expand Up @@ -27,4 +27,14 @@ def create_people_view
v.column :address_id
end
end
def create_or_replace_people_view
ActiveRecord::Base.connection.create_or_replace_view(:v_people,
'select id, first_name, last_name, ssn, address_id from people') do |v|
v.column :id
v.column :f_name
v.column :l_name
v.column :social_security
v.column :address_id
end
end
end

0 comments on commit a91d8ff

Please sign in to comment.