You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a model class that is derived from an abstract class then the automatic determination of the table name does not appear to work. Consider that we have a very minimal table called "colors", with no foreign keys, then with the model classes:
But with schema_associations listed in the Gemfile; using the default configurations, you get an error:
$ rails console
irb> Color.table_name
ColorBase Reverse Foreign Keys (1.4ms) SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema = SCHEMA()
AND referenced_table_schema = table_schema
ORDER BY constraint_name, ordinal_position;
ColorBase Foreign Keys (0.8ms) SHOW CREATE TABLE ``
Mysql2::Error: Incorrect table name '': SHOW CREATE TABLE ``
ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect table name '': SHOW CREATE TABLE ``
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
from /.../activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
from /.../activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:235:in `exec_query'
from /.../schema_plus_core-0.6.0/lib/schema_plus/core/active_record/connection_adapters/mysql2_adapter.rb:51:in `block in exec_query'
...
Interestingly, if you immediately retry the same thing it works:
irb> Color.table_name
Color Reverse Foreign Keys (1.7ms) SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema = SCHEMA()
AND referenced_table_schema = table_schema
ORDER BY constraint_name, ordinal_position;
Color Foreign Keys (0.7ms) SHOW CREATE TABLE `colors`
=> "colors"
There are no problems if do-nothing abstract base class is not in the mix. The only schema_plus gems that are loaded are:
Just poking around in the code I added a one-line patch which appears to work. But as I really don't know how all the code works I have no idea if this is the correct thing to do.
It would be nice to have a clean way to have the functionality of "schema_associations" in a base model class when schema associations are turned off globally and have it inherited. For example:
If you have a model class that is derived from an abstract class then the automatic determination of the table name does not appear to work. Consider that we have a very minimal table called "colors", with no foreign keys, then with the model classes:
Without schema_associations you can enter:
But with schema_associations listed in the Gemfile; using the default configurations, you get an error:
Interestingly, if you immediately retry the same thing it works:
There are no problems if do-nothing abstract base class is not in the mix. The only schema_plus gems that are loaded are:
If I had to guess it seems like an initialization ordering thing, but I don't know the code well enough.
The text was updated successfully, but these errors were encountered: