This project is archived and is in readonly mode.

#2048 ✓invalid
Jeff Schwab

undefined method `quoted_table_name' with model called "schema"

Reported by Jeff Schwab | February 22nd, 2009 @ 11:49 PM | in 2.x

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>)

Comments and changes to this ticket

  • CancelProfileIsBroken

    CancelProfileIsBroken August 5th, 2009 @ 01:51 PM

    • Tag changed from nomethoderror, quoted_table_name, schema to bugmash, nomethoderror, quoted_table_name, schema
  • Nikolay Petrachkov

    Nikolay Petrachkov August 8th, 2009 @ 03:31 PM

    "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'
    
  • Dan Pickett

    Dan Pickett August 8th, 2009 @ 09:57 PM

    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

  • Dmitry Ratnikov

    Dmitry Ratnikov August 9th, 2009 @ 04:50 AM

    +1

    Behavior verified on 2-3-stable.

  • Dmitry Ratnikov

    Dmitry Ratnikov August 9th, 2009 @ 05:04 AM

    -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

  • Rizwan Reza

    Rizwan Reza August 9th, 2009 @ 04:42 PM

    not reproducible

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

  • CancelProfileIsBroken

    CancelProfileIsBroken August 10th, 2009 @ 02:47 AM

    • State changed from “new” to “invalid”
    • Tag changed from bugmash, nomethoderror, quoted_table_name, schema to nomethoderror, quoted_table_name, schema

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages