This project is archived and is in readonly mode.
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
-
Rhett Sutphin April 21st, 2008 @ 11:13 PM
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.
-
josh April 30th, 2008 @ 11:00 PM
- State changed from new to resolved
- Assigned user set to josh
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
- 124 Fixture named accessors do not work when the fixture name is not the table name The underlying cause is similar to ticket #8: @loaded_f...
- 6720 Parameter Filter not working Look at #8 the key is (action_dispatch.request.parameters...
- 6788 Sass::SyntaxError when using CSS "alpha-opacity" property Showing /Users/edison/Sites/beta.foco/app/views/layouts/a...