I have a model with a serialized column of data, and I need to make sure
that certain fields exist in the serialized data depending on different
criteria (I'm using the enum plugin for status)
class Order < Sequel::Model
enum :status, [:draft, :submitted, :approved]
plugin :serialization
serialize_attributes :json, :sales_line
def validate
super
validates_presence :sales_line unless draft?
# How can I validate that the sales lines also have a "sales_qty"
attribute?
end
end
Basically, inside my serialized data of sales lines I have some fields.
Based on the order status I need to make sure that these fields are present:
- "sales_qty" must be filled in unless the order is a draft
- "approved_qty" must be filled in if the order is approved
Doing this if these were fields on a relation or on the order itself is
fairly straight forward but I'm not sure how to do it on serialized data.
Thanks!
--
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.