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.

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

#6479

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.

Reported by joshfng · February 27th, 2011 @ 02:17 PM

State: invalid
Milestone: 3.0.6
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Everton Moreth
    Everton Moreth

    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

    February 28th, 2011 @ 02:00 PM

  2. joshfng
    joshfng

    Any update on what's causing this?

    March 7th, 2011 @ 08:00 PM

  3. joshfng
    joshfng
    • 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

    March 8th, 2011 @ 07:21 PM

  4. joshfng
    joshfng
    • Assigned user changed from Aaron Patterson to Santiago Pastorino

    March 8th, 2011 @ 07:22 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Milestone set to 3.0.6
    • Importance changed from to Low

    March 9th, 2011 @ 12:24 AM

  6. Dan Pickett
    Dan Pickett

    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.

    March 9th, 2011 @ 12:54 AM

  7. joshfng
    joshfng

    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.

    March 9th, 2011 @ 01:01 AM

  8. Santiago Pastorino
    Santiago Pastorino
    • 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.

    March 9th, 2011 @ 06:42 PM