Skip to content

Instantly share code, notes, and snippets.

@bnjamin
Created September 19, 2021 17:40
Show Gist options
  • Save bnjamin/7853d7380b57a000d833e0803deefcd0 to your computer and use it in GitHub Desktop.
Save bnjamin/7853d7380b57a000d833e0803deefcd0 to your computer and use it in GitHub Desktop.
Virtual column rails
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
encoding: "unicode",
database: "activerecord_unittest"
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :virtual_columns, force: true do |t|
t.string :name
t.virtual :upper_name, type: :string, as: "UPPER(name)", stored: true
t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
t.virtual :name_octet_length, type: :integer, as: "OCTET_LENGTH(name)", stored: true
end
end
class VirtualColumn < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_association_stuff
VirtualColumn.create!(name: "Rails")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment