Update foreign key field with NULL value

Forum for posting problems using QxOrm library

Update foreign key field with NULL value

Postby nickla » Wed Sep 26, 2012 7:06 pm

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");
    }
nickla
 
Posts: 52
Joined: Wed Jul 11, 2012 4:19 pm
Location: Russia

Re: Update foreign key field with NULL value

Postby qxorm » Thu Sep 27, 2012 10:10 am

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...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 10 guests