[odb-users] Re: Transform custom type (map) to a single value (json)

Boris Kolpackov boris at codesynthesis.com
Fri Jan 31 07:50:38 EST 2020

Adnan RIHAN <axel50397 at gmail.com> writes:

> Le 29/01/2020 à 19:10, Adnan RIHAN a écrit :
> > Currently, I would like to transform a QMap to/from JSON when using
> > ODB, being able to store an entire object (and its QMap property) to
> > the same table.
> I declared `Schedule::m_times` transient, and declared a virtual
> `Schedule::times` with get/set pragmas. I think it's the right way
> to do it !

Yes, that's one way to do it. You could also map WorkShifts to text
(if you had multiple such members the above approach could become

#pragma db map type(WorkShifts) as(QString) \
  to((?).toJson ())                         \
  from(WorkShifts::fromJson (?))

More information about the odb-users mailing list