Technology and Software

PostgreSQL vs. Rails’s fixtures

Rails’ fixtures don’t always work well. With PostgreSQL I’ve been experiencing a kind of deadlock, where I can’t say neither fixture :t1, :t2 nor fixture :t2, :t1. I’m using foreign keys that refer from :t1 to :t2, a choice that Rails doesn’t look to like much. I’m getting a runtime error anyway: either t1 can’t be populated before t2, because the elements of t2 must be there in advance; or t2 can’t be deleted because t1 has records that refers to it. Rails can’t figure out the appropriate way to load and delete fixtures, even if the documentation is pretty clear that it should with the right order of fixture declarations. Well, it doesn’t. It should be a bug, but how to work around it? Luckily it’s simple, even if I don’t like it much: enabling ON DELETE CASCADE on each foreign key fixes it.
By the way, this is the first time I run into this problem and it’s the first time that I’m using config.active_record.schema_format = :sql instead of config.active_record.schema_format = :db. I can’t easily go back to :db and check, but it might be that the sql schema format doesn’t let Rails grock the db structure well.

Advertisements
Standard