On Mon, Aug 14, 2006 at 10:00:54PM -0700, Chris Wanstrath
wrote:> The hackery is in Blog.create. Have to dance around Camping''s
meta-
> ness and table prefix stuff. Anyone have a better / easier way of
> doing this? I tried a few different approaches but kept coming back
> to this one -- the brute force.
Actually, this would be nice to have around in camping/db.rb.
if Object.const_defined? DrNicMagicModels
DrNicMagicModels::Schema.module_eval <<-LOAD
def self.load_schema
if conn = ActiveRecord::Base.connection
@@models = DrNicMagicModels::ModelHash.new
@@models.merge! conn.tables.inject({}) {|model_list,table_name|
model_list[ActiveRecord::Base.class_name(table_name.split(''_'')[1..-1]*''_'')]
table_name; model_list}
end
end
LOAD
end
Play with it for another week and let''s see if it holds up. If
it''s just 12
lines, then yeah.
_why