This project is archived and is in readonly mode.

#6479 ✓invalid
joshfng

Model associations are trying to select singular table names after 3.0.5 upgrade

Reported by joshfng | February 27th, 2011 @ 02:17 PM | in 3.0.6

Two models Photo and ImageMeta (db tables photos and image_metas). Photo.rb has_one :image_meta. Before upgrade: select * from image_metas where photo_id = photo.id. After 3.0.5 upgrade select * from image_meta where photo_id = photo.id. Fails with mysql error because table image_meta does not exist. Rolled back to 3.0.4 and the problem went away.

Comments and changes to this ticket

  • Everton Moreth

    Everton Moreth February 28th, 2011 @ 02:00 PM

    Same with me...

    Here is some backtrace info:

    57) Topico deve saber quando a ultima resposta foi atualizada
         Failure/Error: Unable to find matching line from backtrace
         Mysql::Error:
           Table 'myproject_test.resposta' doesn't exist
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/connection_adapters/mysql_adapter.rb:287:in `query'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/connection_adapters/mysql_adapter.rb:287:in `execute'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/connection_adapters/mysql_adapter.rb:438:in `columns'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/base.rb:679:in `columns'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:680:in `has_primary_key_column?'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:599:in `insert_fixtures'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:582:in `each'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:582:in `insert_fixtures'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:526:in `create_fixtures'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:526:in `each'
         # /home/emoreth/.rvm/gems/ruby-1.8.7-p330@myproject/gems/activerecord-3.0.5/lib/active_record/fixtures.rb:526:in `create_fixtures'
    

    Table name on select should be "respostas".

    Regards,
    EMoreth

  • joshfng

    joshfng March 7th, 2011 @ 08:00 PM

    Any update on what's causing this?

  • joshfng

    joshfng March 8th, 2011 @ 07:21 PM

    • Assigned user set to “Aaron Patterson”

    Thanks to the guys in IRC we have tracked it down to this commit: https://github.com/rails/rails/commit/1754bd9b208e8d9207c226d1ffb3c...

    My rails generated model was ImageMeta with a table name image_metas. Not it's trying to select image_meta

  • joshfng

    joshfng March 8th, 2011 @ 07:22 PM

    • Assigned user changed from “Aaron Patterson” to “Santiago Pastorino”
  • Santiago Pastorino

    Santiago Pastorino March 9th, 2011 @ 12:24 AM

    • State changed from “new” to “open”
    • Milestone set to 3.0.6
    • Importance changed from “” to “Low”
  • Dan Pickett

    Dan Pickett March 9th, 2011 @ 12:54 AM

    I'm not sure how this is a bug as it relates to English word forms.

    image_meta is a poor model name because meta is not a noun and does not have a plural form.

    Arguably, there should be some locale based defaults for inflections to resolve Everton's issue, but I think the pluralization rules for English words are proper.

    Josh, if you have to use the image_metas table name you could always add a custom inflection to get the behavior you want.

  • joshfng

    joshfng March 9th, 2011 @ 01:01 AM

    Yes I ended up adding an inflector to change meta back to meta. It was poor model naming on my part but also affected other devs so I figured I would keep the ticket open.

  • Santiago Pastorino

    Santiago Pastorino March 9th, 2011 @ 06:42 PM

    • State changed from “open” to “invalid”

    I agree with Dan here, anyways was not a good idea to push this to stable my fault :(.

    Please use your own inflections to fix the problem.

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>

Referenced by

Pages