eladmeidar/rails_indexes

does not work with tableless models

kakra opened this issue · 1 comments

rails_indexes breaks on tableless models with the following error:

(in /home/kakra/git/netactive/abfuhr)
rake aborted!
Mysql::Error: Table 'kakra_abfuhrkalender.tablelesses' doesn't exist: SHOW KEYS FROM `tablelesses`
(See full trace by running task with --trace)

This happens when using a model like this:

class AnonymousSession < Tableless
...
end

class Tableless < ActiveRecord::Base
  def self.columns
    @columns ||= [];
  end
  def self.column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  end
  # Override the save method to prevent exceptions.
  def save(validate = true)
    validate ? valid? : true
  end
end

See http://stackoverflow.com/questions/315850/rails-model-without-database/318919#318919 why such models may be useful. rails_indexes should be able to just ignore these.

well, the convention for creating a "tableless" model is to create the model simply as abstarct by simply specifing:
self.abstract_class = true
in your model.
since there are countless ways to imitate a tableless behaviour, just like you did... i can't really supply a full coverage for every case.
what i will do is to try and provide a better exception handling for these kind of errors.
Thanks.