I have some troubles with this approach for multi-inherited abstract
AbstractModelClass = Class.new(Sequel::Model) do
rescue Sequel::Error => error # because there is no `dataset?` method,
and `dataset` getter raises error
raise error unless error.message.start_with?('No dataset associated')
AbstractModelClassWithAdditionalFeature = Class.new(AbstractModelClass) do
class Child < AbstractModelClass
On Wednesday, May 30, 2012 at 9:49:08 PM UTC+3, Jeremy Evans wrote:
> On Wednesday, May 30, 2012 10:20:38 AM UTC-7, Michael Granger wrote:
>> > On Saturday, May 26, 2012 7:01:48 PM UTC-7, Jeremy Evans wrote:
>> > > On Friday, May 25, 2012 1:28:43 PM UTC-7, Michael Granger wrote:
>> > > Even though it's an unsupported use, subclassing Sequel::Model works
>> quite well if you're careful. I do it in several projects in which I want
>> to use Sequel::Model, but I can't know where the database is until runtime
>> (e.g., connect info is in a config file, etc.).
>> > This is probably different from what the original poster is asking. In
>> your case, your model has a backing table, it just isn't known until
>> runtime. He appears to be requesting a way to use a model without a
>> backing table at all.
>> Looking back at what I wrote, I didn't explain myself well, but my
>> case is the same as his *in addition* to runtime loading: both of the
>> above cases subclass Sequel::Model, but don't have a backing table,
>> and then all other model classes inherit from it instead of
>> Sequel::Model directly. Mongrel2::Config is the abstract class in the
>> first case, and WordNet::Model in the second. So instead of:
>> ModelClass < (anonymous model class) < Sequel::Model
>> the inheritance ends up being:
>> ConcreteModelClass < (anonymous model class) < AbstractModelClass <
> Ah. Apparently I misinterpreted the original post. Having an abstract
> model class without a backing table is completely supported, as long as you
> only instantiate subclasses that have a backing table. The recommended way
> to do this in Sequel is to use Class.new:
> AbstractModelClass = Class.new(Sequel::Model)
> class AbstractModelClass
> # ...
> The problem with the regular form:
> class AbstractModelClass < Sequel::Model
> Is that it is going to assume that AbstractModelClass has a dataset
> associated with it, when it should not.
> Sorry for the misunderstanding.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.