This project is archived and is in readonly mode.

#8 ✓resolved
Rhett Sutphin

Fixture caching does not work with prefixed/suffixed tables

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

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.

Comments and changes to this ticket

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

Referenced by

Pages