On Aug 7, 9:25 pm, russm <russm-goo...@slofith.org> wrote: > I'm trying to port some app infrastructure from an old ad-hoc system > over to Sequel, and have hit a couple of issues with the class table > inheritance plugin and the schema generator. The goal is a CTI > structured database with UUID primary keys, where the parent object > type doesn't have to know what's inheriting from it. > > So, first, is there any way of specifying a foreign_key that's neither > an integer nor a composite key? At the moment I'm using the composite > foreign key syntax but specifying only the single UUID column :id in > the keys array - this appears to work but seems a bit unpleasant.
Yes: foreign_key :column, :table, :type=>:uuid > With the CTI plugin, do the child classes need to be specified in the > table map? I'd rather not have to push knowledge about the class > hierarchy up into the top level class. It's only necessary if the implicit table names do not match the database table names. Because using set_dataset in subclasses would screw up the plugin, you must set the table name in the :table_map so that the plugin can assign the correct table name. > Finally, I can't work out how to inherit from my base object type when > my classes are namespaced and I have custom table names. I have > > module ACS > class Object < Sequel::Model(:acs_objects) > plugin :class_table_inheritance, :key => :kind > plugin :timestamps > > def before_create > self.id = UUIDTools::UUID.random_create > end > end > end > > If I try to define a subclass like so - > > module ACS > module Media > class File < ACS::Object(:acs_media_files) > end > end > end That doesn't work because ACS::Object is a class not a method. You probably think this would work because Sequel::Model(:table) works, but that is because Sequel::Model is both a class and a method. Anyway, in order to override the implicit class name, you need to use the :table_map option in the plugin. > I get "NoMethodError: undefined method `Object' for ACS:Module" (which > makes sense, since ACS::Object isn't a method, though the PoLS > suggests it should work). If I do this instead - > > module ACS > module Media > class File < ACS::Object > set_dataset :acs_media_files > end > end > end > > I get a trace back through the sqlite adapter with > "Sequel::DatabaseError: SQLite3::SQLException: no such table: files". > Is there a way to specify a custom table name for CTI subclasses? Like I said, you can't use set_dataset in CTI subclasses. This situation is why you need the :table_map option. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to sequel-t...@googlegroups.com. To unsubscribe from this group, send email to sequel-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.