1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Incorporate feedback

This commit is contained in:
Stefan Stüben 2021-04-06 19:04:50 +02:00
parent 2cf41d7a5e
commit 64fd666e16
6 changed files with 16 additions and 4 deletions

View file

@ -6,7 +6,7 @@
```ruby
create_table :users do |t|
t.string :name
t.virtual :name_upcased, type: :string, as: 'upper(name)'
t.virtual :name_upcased, type: :string, as: 'upper(name)', stored: true
end
```

View file

@ -456,7 +456,7 @@ module ActiveRecord
end
def build_fixture_sql(fixtures, table_name)
columns = schema_cache.columns_hash(table_name)
columns = schema_cache.columns_hash(table_name).reject { |_, column| supports_virtual_columns? && column.virtual? }
values_list = fixtures.map do |fixture|
fixture = fixture.stringify_keys

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
require "active_support/core_ext/object/blank"
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
@ -17,7 +19,8 @@ module ActiveRecord
end
def virtual?
@generated == "s"
# We assume every generated column is virtual, no matter the concrete type
@generated.present?
end
def has_default?

View file

@ -69,5 +69,9 @@ if ActiveRecord::Base.connection.supports_virtual_columns?
assert_match(/t\.virtual\s+"name_length",\s+type: :integer,\s+as: "length\(\(name\)::text\)", stored: true$/i, output)
assert_match(/t\.virtual\s+"name_octet_length",\s+type: :integer,\s+as: "octet_length\(\(name\)::text\)", stored: true$/i, output)
end
def test_build_fixture_sql
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :virtual_columns)
end
end
end

View file

@ -0,0 +1,5 @@
one:
name: hello
two:
name: world

View file

@ -512,7 +512,7 @@ NOTE: Generated columns are supported since version 12.0 of PostgreSQL.
# db/migrate/20131220144913_create_users.rb
create_table :users do |t|
t.string :name
t.virtual :name_upcased, type: :string, as: 'upper(name)'
t.virtual :name_upcased, type: :string, as: 'upper(name)', stored: true
end
# app/models/user.rb