Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

undefined method `quoted_table_name' with model called "schema"

#2048

Rails seems to have a problem with any model called Schema, when another model has a has_and_belong_to_many relationship with Schema.

Generate two scaffolds, one of which has a model called Schema. Generate a migration for a join table, including box_id and schema_id columns. Add has_and_belongs_to_many calls to the models.

Run the migrations and start the server. Create a record of the non-Schema type. Try to destroy that record. The server fails with an error message like:

NoMethodError (undefined method quoted_table_name' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x2470624>)

Reported by Jeff Schwab · February 22nd, 2009 @ 11:49 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from nomethoderror, quoted_table_name, schema to bugmash, nomethoderror, quoted_table_name, schema

    August 5th, 2009 @ 01:51 PM

  2. Nikolay Petrachkov
    Nikolay Petrachkov

    "verified" with instructions above.

    Same error with MySQL and PostgreSQL.

    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `block in method_missing'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `block in say_with_time'
    /usr/local/lib/ruby/1.9.1/benchmark.rb:294:in `measure'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `method_missing'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/reflection.rb:187:in `quoted_table_name'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb:86:in `construct_sql'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:21:in `initialize'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/associations.rb:1265:in `new'
    /home/jastix/projects/bugmash/2048/schem/vendor/rails/activerecord/lib/active_record/associations.rb:1265:in `block in collection_reader_method'
    (eval):3:in `destroy_without_callbacks'
    /home/jastix/projects/bugmash/2048/schem/app/controllers/plans_controller.rb:62:in `destroy'
    

    August 8th, 2009 @ 03:31 PM

  3. Dan Pickett
    Dan Pickett

    not reproducible

    I was able to create a new rails app with a schema model and a user model - upon creating and destroying a user I did not get any errors

    August 8th, 2009 @ 09:57 PM

  4. Dmitry Ratnikov
    Dmitry Ratnikov

    +1

    Behavior verified on 2-3-stable.

    August 9th, 2009 @ 04:50 AM

  5. Dmitry Ratnikov
    Dmitry Ratnikov

    -1 The error stems from a reflection instance returning ActiveRecord::Schema (rather than regular Schema) as klass.

    As a work around, use:

    class User < ActiveRecord::Base
    has_and_belongs_to_many :schemas, :class_name => "::Schema" end

    August 9th, 2009 @ 05:04 AM

  6. Rizwan Reza
    Rizwan Reza

    not reproducible

    -1 It is evident that ActiveRecord will have problems with tables that have matching names to its internal classes.

    August 9th, 2009 @ 04:42 PM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to invalid
    • Tag changed from bugmash, nomethoderror, quoted_table_name, schema to nomethoderror, quoted_table_name, schema

    August 10th, 2009 @ 02:47 AM