PeterHamilton/citier — Issue #36: schema.db dump create_views aren't order by class inheritance
Author: jonlhouse
Created: 2011-10-22 23:07:44+00:00
State: open

I'm not 100% sure about this as a bug in general or on my end but here's the situation:

It looks like the schema.rb "create_view" entries are populated alphabetically. This is a problem when a child model references a parent model who's view is not yet defined.

Here's my example:
I have data model for literature citations in which `class EPeriodicalCitation < PeridoicalCitation`

``` ruby
create_view "view_e_periodical_citations", "select `view_periodical_citations`.`id` AS `id` (REST OF LINE REMOVED) do |v|
# column definition
end

create_view "view_periodical_citations", "select `view_authored_citations`.`id` (REST OF LINE REMOVED) do |v|
# column definition
end
```

Since 'view_e_periodical_citations' is < 'view_periodical_citations' it gets output first and causes an ERROR when `rake db:test:prepare` is run.

The simple fix for me was to reorder the schema.rb file so that base views are referenced before child views. I don't know if a general fix based on class hierarchy is easy or difficult but I thought I'd pass along the message.