ruby-on-railsrubyinheritanceclass-table-inheritance

No implicit conversion of nil into String. dbview_cti


I use dbview_cti gem to make Class Table Inheritance (CTI). I have two classes Person(abstract class) and Client(inherits Person).

Problem:

When I try make rake db:migrate, console write this error:

StandardError: An error has occurred, this and all later migrations canceled:

    no implicit conversion of nil into String ../postgresql/utils.rb:24:in `quote_ident'

Model Person

class Person < ActiveRecord::Base
  self.abstract_class = true
  cti_base_class
end

Model Client

class Client < Person
  cti_derived_class
end

Migration create_people

class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table :persons do |t|
      t.string :pesel, null: false
      t.string :first_name, null: false
      t.string :last_name, null: false
      t.string :email, null: false
      t.date :data_of_birth, null: false
      t.string :password_digest, null: false
      t.timestamps null: false
    end
  end

  def self.down
    drop_table :persons
  end
end

Migration create_clients

class CreateClients < ActiveRecord::Migration
  def change
    create_table :clients do |t|
      t.references :person
      t.timestamps null: false
    end

    cti_create_view('Client')
  end
end

More details about error:

>     == 20160223135814 CreateClients: migrating ====================================
>     -- create_table(:clients)
>        -> 0.0348s
>     -- cti_create_view("Client")
>     rake aborted!
>     StandardError: An error has occurred, this and all later migrations canceled:
>     
>     no implicit conversion of nil into String/home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in
> `quote_ident'
>     /home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in
> `quoted'
>     /home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/quoting.rb:31:in
> `quote_table_name'
>     /home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:738:in `column_definitions'
>     /home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:186:in
> `columns'
>     /home/lukas/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/schema_cache.rb:43:in
> `columns'

Any idea where is wrong?


Solution

  • Your Person class is marked as an abstract class and as such its table_name is nil. In general abstract_class has been added so gems can define their own subclasses of ActiveRecord::Base that can be then inherited in the application without causing STI logic to get in. You can either make it non-abstract or set back the table name for inheritance:

    class Person < ActiveRecord::Base
      self.abstract_class = true
      self.table_name = 'people'
      cti_base_class
    end