Hi,

I solved an issue I had but I'm not sure if it's the expected behaviour or
not. Let me explain.

I realized that model values in plugins are not inherited by default when
subclassing a model.
That is:

class MyModel < Sequel::Model
>   plugin MyPlugin, foo: { a: 1 }
> end

class MyInherited < MyModel
> end


If MyPlugin stores the foo value in a @foo variable, it is nil in
MyInherited.

That's where the doc kicks in
http://sequel.jeremyevans.net/rdoc/files/doc/model_plugins_rdoc.html#label-Handling+Subclasses,
and adding

Sequel::Plugins.inherited_instance_variables(self, :@foo => nil)


in the plugin's ClassMethods fixes the issue.

But I wanted to clarify if it's expected. The doc states "*instead of model
subclasses asking their parent class for a value if they don't have it
defined, the value is automatically copied from the parent class to the
subclass when the subclass is created*".

So I would expect that I don't have to call inherited_instance_variables
myself: the default would be the `nil` option.

I suspect it's expected behaviour though, and the doc could be updated to
"automatically copied *if you specify an inheritance policy through
inherited_instance_variables*".

Let me know if my understanding is correct and I can submit this small doc
PR.

Best,


*Michael MONERAU*
Qontrol <https://www.qontrol.io>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CAAkfp_QkW6nXZRFvSjYfHeW5Mb6ETx-9c2DdQQHuhHd-p0iwog%40mail.gmail.com.

Reply via email to