Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.db dump create_views aren't order by class inheritance #36

Open
jonlhouse opened this issue Oct 22, 2011 · 2 comments
Open

schema.db dump create_views aren't order by class inheritance #36

jonlhouse opened this issue Oct 22, 2011 · 2 comments

Comments

@jonlhouse
Copy link

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

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.

@raphaelpereira
Copy link

You can specify create_view order in config/application.rb

# Configure VIEWs creation orders
ActiveRecord::SchemaDumper.view_creation_order = ['view_e_periodical_citations','view_periodical_citations']

@robotex82
Copy link

This seems to be a general problem. I'm building an example app, following the docs and I'm having the same problem, when trying to do

rake db:test:prepare

It seems that views are dumped alphabetically by default. The real solution would be to follow the migration order. Any ideas how to achieve this automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants