SchemaPlus / schema_plus

SchemaPlus provides a collection of enhancements and extensions to ActiveRecord
Other
681 stars 86 forks source link

schema_plus 1.8.x: jruby + postgresql with activerecord-jdbcpostgresql-adpater > 1.3.14 #214

Open ronen opened 9 years ago

ronen commented 9 years ago

Something in activerecord-jdbcpostgresql-adapter changed in 1.3.15 or 1.3.16, causing this error when using schema_plus 1.8.x:

ArgumentError:
     wrong number of arguments calling `initialize` (7 for 4)
     # .../.gem/jruby/1.9.3/gems/activerecord-jdbc-adapter-1.3.16/lib/arjdbc/postgresql/adapter.rb:1164:in `columns'
    etc.

due to some sort of conflict caused when including schema_plus's Column module into ActiveRecord's.

I've temporarily removed jruby + postgresql from the build (commit 2a05925e23c320613859b103b6a62e4af5bd564b). But I'm not likely to have time to chase down the problem any time soon.

@donv, do you want to look into it?

lfidnl commented 9 years ago

Hi! I figured out this issue. In activerecord-jdbc <= 1.3.12 initialize method was described in PostgreSQLColumn class. But in activerecord-jdbc > 1.3.12 initialize method was moved to Arjdbc::ArJdbc::PostgreSQL module.

So, after including SchemaPlus::ConnectionAdapters::PostegreSQLColumn: for <= 1.3.12 ActiveRecord::ConnectionAdapters::PostgreSQLColumn#initialize will be called from ActiveRecord::ConnectionAdapters::PostgreSQLColumn, because ruby will search for #initialize method through all ancestors and will find it in ActiveRecord::ConnectionAdapters::PostgreSQLColumn class.

for > 1.3.12 ActiveRecord::ConnectionAdapters::PostgreSQLColumn#initialize will be called from SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn, because ruby will search for #initialize method through all ancestors and it won`t be able to find it in ActiveRecord::ConnectionAdapters::PostgreSQLColumn and will continue to search in SchemaPlus::ConnectionAdapters::PostegreSQLColumn ancestor. SchemaPlus::ConnectionAdapters::PostegreSQLColumn is the next ancestor because this extension was included in the last turn.

The solution is to include SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn after Arjdbc::ArJdbc::PostgreSQL, but I can't understand how to do this.

ronen commented 9 years ago

@lfidnl thanks for tracking that down.

The solution is to include SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn after Arjdbc::ArJdbc::PostgreSQL, but I can't understand how to do this.

Or maybe include SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn into Arjdbc::ArJdbc::PostgreSQL::Column instead of into ActiveRecord::ConnectionAdapters::PostgreSQLColumn?

Unfortunately I'm not a jruby user, and don't have time to look into this myself; plus I'm mostly maintaining schema_plus 2.0 rather than 1.8 -- but I'm happy to accept a PR if you get it to work!