petehamilton / citier

CITIER (Class Inheritance & Table Inheritance Embeddings for Rails) is a solution for simple Multiple Class Inheritance in Rails.
88 stars 24 forks source link

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

Open jonlhouse opened 12 years ago

jonlhouse commented 12 years ago

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 commented 12 years ago

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 commented 11 years ago

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?