Ah clever!

On a related note, I have struggled in the past to `create` a new model. I
would have liked that it is possible to call `BaseClass.create` and the
actually created class is the correct precise class given on the STI key
value. It is important when serialization occurs depending on the
instantiated class for example.

Adding a `create_precise` method that would do the lookup would also be
acceptable.

Is there a clever way to achieve that (without looking up the correct class
myself at creation site), or would you consider adding such a feature to
the plugin?

Best,
Michael





Le ven. 12 févr. 2021 à 16:52, Jeremy Evans <[email protected]> a
écrit :

> On Fri, Feb 12, 2021 at 4:34 AM '[email protected]' via sequel-talk <
> [email protected]> wrote:
>
>> Hello,
>> I'd like to disable a possibility for creating a model directly from STI
>> base class. Any idea how to do that properly?
>>
>> Maybe you're asking why I need that. Imagine that there are some
>> validations defined in subclasses but if you create model directly from a
>> base class, then those validations are not performed...
>>
>
> Something like this should work:
>
> class BaseClass < Sequel::Model
>   def before_create
>     raise if instance_of?(BaseClass)
>     super
>   end
> end
>
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/sequel-talk/CADGZSSfDoGbVF5G7Jd%2BPxhc4H25%2ByU_JQ9N8PAo0kUGL82HnhA%40mail.gmail.com
> <https://groups.google.com/d/msgid/sequel-talk/CADGZSSfDoGbVF5G7Jd%2BPxhc4H25%2ByU_JQ9N8PAo0kUGL82HnhA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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_QgQ6gpeeG%2BwJpgitbyzyCJ6%2BK7C_hT-LUYBQFXATyFYg%40mail.gmail.com.

Reply via email to