Convert/serialize/marshal column type to richer type and back #2258
Closed
davetron5000
started this conversation in
General
Replies: 2 comments
-
You probably want to use the serialization plugin. In pretty much all cases in Sequel, you can override the method, then call super to get the default behavior (methods defined automatically are generally defined in a module included in the class). |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ah, ok, that worked! class Widget # ...
plugin :serialization
serialize_attributes [
:to_s.to_proc,
TimeOfDay.method(:parse),
], :check_inventory_time_of_day
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have scoured the docs and cannot find if there is a way to do this. Essentially I want to have the attribute method of a model return a custom type based on the underlying database type and back again.
For example, suppose my
Widget
model has thecheck_inventory_time_of_day
attribute, that stores a time of day in 24 hour time, like"4:30"
I store that as atext
in the database. Suppose I have a classTimeOfDay
that can interpret that value.I'd like:
I can't find docs on how the attr readers/writers are created to know if they are safe to override and if they are all that needs overriding.
Beta Was this translation helpful? Give feedback.
All reactions