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 < 
> Sequel::Model 
>

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
    # ...
  end 

The problem with the regular form:

  class AbstractModelClass < Sequel::Model
  end

Is that it is going to assume that AbstractModelClass has a dataset 
associated with it, when it should not.

Sorry for the misunderstanding.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/p1iqO57cwqwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to