[Nitro] OG vs Active Record
Jonathan Buch
john at oxyliquit.de
Fri Aug 24 14:00:39 EDT 2007
Hi,
> I would like to see the code you are using.
the meat of all it is:
sql.rb:
def og_create_schema(store)
return unless Og.create_schema
if self.class.const_defined?(:OG_SCHEMA)
store.create_custom_schema(self.class.const_get(:OG_SCHEMA))
else
unless self.class.schema_inheritance_child?
store.create_table(self.class)
store.create_table_indices(self.class)
store.create_table_joins(self.class)
end
store.evolve_schema(self.class)
end
end
This can already be used like this:
class MyUserView
attr_accessor :a, String
OG_SCHEMA = <<-SQL
CREATE VIEW ogmyuserview AS SELECT a FROM foo
SQL
end
Another bit is quite necessary though:
manager.rb:
def manage_classes(*args)
# ...
classes = classes.sort_by {|x| x.const_defined?(:OG_SCHEMA) ? 1 : 0 }
classes.each { |c| manage(c) }
end
Which moves the enchanting of 'custom' classes to the back
because they might depend on other tables which have to be
created/evolved first. (might fail due to interdependencies
between views, this is one of the 'glitches')
That's basically it, my very own auto-view-creator by adding
5 lines. :P
Jo
--
Feel the love
http://pinkjuice.com/pics/ruby.png
More information about the Nitro-general
mailing list