On Feb 6, 4:34 am, Tom Wardrop <[email protected]> wrote:
> In the mean time, to get this fixed so I can move on, I'd like to sub-
> class Sequel::Model into something like MyCustomBaseClass, so I can
> override the #implicit_table_name method without overriding the
> original, e.g.
>
> class MyCustomBaseClass < Sequel::Model
> remove_instance_variable(:@dataset)
> # <override implicit_table_name here>
> end
>
> class Person < MyCustomBaseClass
> primary_key :id
> end
>
> From looking at the code, removing the @dataset instance variable
> seems like the only thing I need to do for this to work (a quick test
> confirmed it worked, as far as I can tell). Is this the best way to
> make a custom base class from Sequel::Model, or is there a better way?
I'd recommend the following:
MyCustomBaseClass = Class.new(Sequel::Model)
# <override implicit_table_name here>
end
class Person < MyCustomBaseClass
primary_key :id
end
Using the anonymous class syntax makes it so Sequel won't
automatically associate a dataset with the model.
I don't consider a overriding a single, simple method to be very
arduous, and such an override is very unlikely to break in future
versions, so that's the officially supported way.
The association methods already accept multiple arguments, so I can't
modify that API to accept multiple models at once. However, creating
a plugin that adds plural forms of the add_/remove_ association
methods that accept an array of model instances is fairly trivial.
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 [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.