Page 1 of 1

Update foreign key field with NULL value

PostPosted: Wed Sep 26, 2012 7:06 pm
by nickla
I have such table relation:

order.driver_id = driver.id

I need to update foreign key field order.driver_id with NULL. How can i do this?

i found https://www.qxorm.com/forum/phpbb/viewtopic.php?f=2&t=49 this topic but it is useless b\c :

Code: Select all
    template <> void register_class(QxClass<Order> & t)
    {
        // ... driver_id is not an ordinary field..
        t.relationManyToOne(& Order::m_Driver, "driver_id");
    }

Re: Update foreign key field with NULL value

PostPosted: Thu Sep 27, 2012 10:10 am
by qxorm
Hi,

Now, with QxOrm 1.2.4, you can use boost::optional type to manage NULL database value without using QVariant type.
So, you have to define in your Order class your Order::m_Driver property using boost::optional template.
More details about boost::optional here : http://www.boost.org/doc/libs/1_51_0/li ... index.html

Or you can define m_Driver as a pointer (or a smart pointer) => if the pointer is NULL, the correct value should be inserted into database...