13 #ifndef __UT_ORMFIELD_H__
14 #define __UT_ORMFIELD_H__
72 unsigned props = UT_ORMColumn::Properties::Empty,
75 , myFieldPtr(std::move(adapter))
80 return myFieldPtr.get();
90 template <
typename Cls,
typename MemberT>
103 MemberT Cls::*member_ptr,
106 auto adapter = UTmakeUnique<UT_ORMBasicFieldAdapter<Cls, MemberT>>(
114 return UTsqlOrmColumnType<MemberT>();
119 MemberT&
v = this->
field(obj);
126 MemberT&
v = this->
field(obj);
142 Cls* cls =
static_cast<Cls*
>(obj);
143 return (cls->*myMemberPtr);
147 MemberT Cls::*myMemberPtr;
150 template <
typename Cls>
152 template <
typename Cls>
154 template <
typename Cls>
156 template <
typename Cls>
159 template <
typename ModelT>
173 return myID == rhs.myID;
177 return !(*
this == rhs);
188 return myValue.get();
204 auto&& meta = ModelT::metaInfo();
207 if (
auto fadp = dynamic_cast<foreign_field_t*>(adapter); fadp)
210 myValue = UTmakeUnique<ModelT>(
value);
223 if (
auto&& opt = ModelT::fetch(myID, ec); opt)
225 myValue = UTmakeUnique<ModelT>(opt.value());
233 template <
typename Cls,
typename ForeignKey>
239 using id_t =
typename ForeignKey::foreign_key_t;
242 : myMemberPtr(member_ptr)
247 ForeignKey Cls::*member_ptr,
251 auto&& meta = model_t::metaInfo();
255 = UTmakeUnique<UT_ORMForeignKeyFieldAdapter<Cls, ForeignKey>>(
258 col.setAsForeignKey(meta.tableName(), pk_col->
name());
259 col.setOnDelete(ondelete);
266 return UTsqlOrmColumnType<id_t>();
286 if (ondelete != UT_ORMColumn::OnDelete::DoNothing)
288 ForeignKey&
f =
field(obj);
296 Cls* cls =
static_cast<Cls*
>(obj);
297 return (cls->*myMemberPtr);
301 ForeignKey Cls::*myMemberPtr;
304 #endif // __UT_ORMFIELD_H__
ForeignKey & field(void *obj)
UT_IORMFieldAdapter * adapter() const
const UT_StringHolder & name() const
const UT_ErrorCode & getError() const
UT_ORMColumn::Type sqlType() const override
GLsizei const GLfloat * value
typename ModelT::Meta::primary_key_t foreign_key_t
bool bind(int idx, null_tag_t)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
void bind(void *obj, UT_SqlStatement &stmt, int bind_index, UT_ErrorCode &ec) override
virtual void onDelete(void *obj, UT_ORMColumn::OnDelete ondelete, UT_ErrorCode &ec)
UT_ORMForeignKeyField()=default
typename ForeignKey::foreign_key_t id_t
void setValue(const ModelT &value)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
bool operator==(const UT_ORMForeignKeyField &rhs) const
UT_ORMColumn::Type sqlType() const override
void load(void *obj, UT_SqlStatement &stmt, int index, UT_ErrorCode &ec) override
UT_ORMForeignKeyField(foreign_key_t pk)
typename ForeignKey::model_t model_t
UT_IORMFieldAdapter * adapter()
MemberT & field(void *obj)
void bind(void *obj, UT_SqlStatement &stmt, int index, UT_ErrorCode &ec) override
static UT_ORMFieldColumn createColumn(const UT_StringHolder &name, ForeignKey Cls::*member_ptr, unsigned props, UT_ORMColumn::OnDelete ondelete)
MemberT & getValue(void *obj)
GLuint const GLchar * name
static UT_ORMFieldColumn createColumn(const UT_StringHolder &name, MemberT Cls::*member_ptr, unsigned props)
UT_ORMFieldColumn(const UT_StringHolder &name, UT_UniquePtr< UT_IORMFieldAdapter > adapter, unsigned props=UT_ORMColumn::Properties::Empty, UT_ORMColumn::OnDelete ondelete=UT_ORMColumn::OnDelete::DoNothing)
std::error_code UT_ErrorCode
UT_ORMBasicFieldAdapter(MemberT Cls::*member_ptr)
LeafData & operator=(const LeafData &)=delete
UT_UniquePtr< UT_IORMFieldAdapter > myFieldPtr
Class to store JSON objects as C++ objects.
void setValue(void *obj, const MemberT &t)
bool operator!=(const UT_ORMForeignKeyField &rhs) const
void onDelete(void *obj, UT_ORMColumn::OnDelete ondelete, UT_ErrorCode &ec) override
UT_ORMForeignKeyFieldAdapter(ForeignKey Cls::*member_ptr)
void setId(const foreign_key_t &id)
void load(void *obj, UT_SqlStatement &stmt, int index, UT_ErrorCode &ec) override
GLenum GLuint GLsizei const GLenum * props