Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `adapter_name' for nil:NilClass #32

Open
medvedev84 opened this issue Jul 23, 2013 · 2 comments
Open

undefined method `adapter_name' for nil:NilClass #32

medvedev84 opened this issue Jul 23, 2013 · 2 comments

Comments

@medvedev84
Copy link

I'm trying to use activeuuid with rails 4.0.0. I have created migration according to example, then run it and got a error: "undefined method `adapter_name' for nil:NilClass".

Then I checke stacktrace and found next:
undefined method adapter_name' for nil:NilClass at /activeuuid-0.4.0/lib/activeuuid/patches.rb:11:inblock in uuid'
/activeuuid-0.4.0/lib/activeuuid/patches.rb:10:in each' /activeuuid-0.4.0/lib/activeuuid/patches.rb:10:inuuid'

When I opened patches.rb file I have found next row:
type = @base.adapter_name.downcase == 'postgresql' ? 'uuid' : 'binary(16)'

It seems like @base variable have not been initialized and I have no idea whre it from! Since I'm working with mysql, I just commented this row and inserted new one:
type = 'binary(16)'

But this is just a ugly hack, which should be fixed.

@damncabbage
Copy link

So activerecord-4.0.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb defines ActiveRecord::ConnectionAdapters::Table and ...::TableDefinition.

The problem is that Table does have a @base, but TableDefinition doesn't. At the bottom of activeuuid-0.4.0/lib/activeuuid/patches.rb we have:

ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition

Same method inclusion, different host class with differing interface. Table doesn't have a way to tell what database it's running under, so I'm not sure how to fix it.

The Postgres adapter has native UUID column support; it's perhaps useful to look to that for inspiration as to how to emulate it for the others, instead of monkey-patching Table and TableDefinition directly.

@patchfx
Copy link

patchfx commented Nov 25, 2013

I managed to overcome this error by changing the line to:

type = ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql' ? 'uuid' : 'binary(16)'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants