On Thursday, April 27, 2017 at 7:18:51 AM UTC-7, Samuel Nilsson wrote:
>
> Hi,
>
> What is the preferred way of introducing some sort of "Base Model" which
> common dataset methods? Ideally I would like to something like:
>
> class Base < Sequel::Model
> dataset_methods do
> def foo
> ..
> end
>
> end
>
> def common_method; end;
> end
>
> class Post < Base[:posts]; end;
>
> but then Sequel will start looking for a table called "bases".. So my
> current solution is to create a plugin which contains all the dataset
> methods I need and then use mixins to get shared methods into every model
> class. It works but it ain't pretty!
>
> Better solutions?
>
Just use an anonymous class:
Base = Class.new(Sequel::Model) do
# ...
end
Then your models can inherit from Base and everything should work. You can
also use:
class Foo < Base::Model(:some_table)
end
to customize the table while still inheriting from Base
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.