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.

Fixture caching does not work with prefixed/suffixed tables

#8

The fixture caching introduced with Rails 2 doesn't work if your project uses ActiveRecord::Base.table_name_prefix (or _suffix). You will get a NoMethodError with a stacktrace like this:

You have a nil object when you didn't expect it!

The error occurred while evaluating nil.table_name

proj/vendor/rails/activerecord/lib/active_record/fixtures.rb:1003:in `load_fixtures'

proj/vendor/rails/activerecord/lib/active_record/fixtures.rb:1003:in `each'

proj/vendor/rails/activerecord/lib/active_record/fixtures.rb:1003:in `load_fixtures'

proj/vendor/rails/activerecord/lib/active_record/fixtures.rb:941:in `setup'

...and so on.

The problem is that the fixtures are stored in the cache using the actual table name (i.e., with the prefix and/or suffix), but looked up using the fixture name (without the prefix or suffix).

A workaround is to use set_fixture_class, but since the table names all follow a pattern, this is not very DRY. A better solution would be to index the cache by the fixture name instead of the table name. Patch coming soon.

Reported by Rhett Sutphin · April 16th, 2008 @ 05:18 PM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Rhett Sutphin
    Rhett Sutphin

    I've fixed this in a fork of the 2-0-branch on github. The fix is present in this tree (and is the only change):

    http://github.com/rsutphin/rails...

    I'm not sure if this is the right way to submit git-based patches, so I'm attaching a traditional patch, too.

    April 21st, 2008 @ 11:13 PM

  2. josh
    josh
    • State changed from new to resolved
    • Assigned user set to josh

    April 30th, 2008 @ 11:00 PM