Skip to content


Fixes for Rails 2 / Foreign Keys / Empty fixture directories #6

merged 1 commit into from

2 participants


These changes allow Rails 2 users, users with foreign key constraints and users with empty fixture directories to use FixtureBuilder.


is it possible to apply the fix to master branch as it stands? since you are more familiar with the change it might be easier for you to perform the merge at your end first. there has been a pretty big refectoring done so I'm not sure how cleanly this patch will merge.


Here's the only piece that doesn't seem like it was covered from your recent commits. I tried testing it, but SQLite doesn't have true foreign key constraints, so I couldn't actually get a failing test. I could have just asserted that the disable_referential_integrity method was called, but that seemed dumb.

For the record, the referential integrity change is to make it so that you can delete tables that have foreign keys and data is still referenced by child tables (which happens when there is existing data left in the db after a test run).

CREATE TABLE magical_creatures(
  id serial

CREATE TABLE unicorns(
  magical_creature_id INTEGER,
  FOREIGN KEY(magical_creature_id) REFERENCES magical_creatures(id)

insert into magical_creatures(id) values (1);

insert into unicorns(magical_creature_id) values (1);

drop table magical_creatures; --<< this should raise an error (and does in postgres) but does not

If you need a test in order to apply the patch, I'll have to add a dependency on postgres for the test suite. Let me know what you'd like to do.


this seems fine to me, as long as it works in a repository somewhere with this portion of code, its probably to ok to skip the postgres dependency.

i'll merge it now then push a new version, if you could let me know if the github version works fine with a test repo i'll release a new gem.

@rdy rdy merged commit 2d96ffd into rdy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 19, 2011
  1. @zilkey
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/fixture_builder/builder.rb
4 lib/fixture_builder/builder.rb
@@ -54,7 +54,9 @@ def clean_out_old_data
def delete_tables
- tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % ActiveRecord::Base.connection.quote_table_name(t)) }
+ ActiveRecord::Base.connection.disable_referential_integrity do
+ tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % ActiveRecord::Base.connection.quote_table_name(t)) }
+ end
def delete_yml_files
Something went wrong with that request. Please try again.