I've got a small test project to evaluate QxOrm. The use case is an on-demand production with a few objects. The whole project code is also attached to this post as well, see below.
I created 3 Address objects (one invoice Address with a 1:1 relation to a Customer object, two delivery Address objects with a 1:1 relation to an Order object each):
- Code: Select all
CustomerPtr customer(new Customer());
...
AddressPtr invoiceAddress(new Address());
invoiceAddress->setStreet("Musterstrasse");
...
OrderPtr order(new Order());
order->setCustomer(customer);
OrderPtr order2(new Order());
order2->setCustomer(customer);
AddressPtr deliveryAddress(new Address());
deliveryAddress->setStreet("Lieferstrasse");
...
AddressPtr deliveryAddress2(new Address());
deliveryAddress2->setStreet("Anderelieferstrasse");
...
deliveryAddress->setOrder(order);
order->setDeliveryAddress(deliveryAddress);
deliveryAddress2->setOrder(order2);
order2->setDeliveryAddress(deliveryAddress2);
// persist customer, adresses and order to database
daoError = qx::dao::save(customer);
daoError = qx::dao::save(invoiceAddress);
daoError = qx::dao::save(order);
daoError = qx::dao::save(deliveryAddress);
daoError = qx::dao::save(order2);
daoError = qx::dao::save(deliveryAddress2);
AddressVec addresses;
qx::dao::fetch_all_with_all_relation(addresses);
for (auto address : addresses)
{
qInfo() << "################### " << address->order()->id() << address->id() << address->street();
}
The problem is the last part: I try to get all Address entries from tha database and check them to see whether they are connected to an order (which makes them a delivery address, invoice addresses don't have a related order). The output is:
- Code: Select all
[QxOrm] sql query (total: 0.923 ms, db_exec: 0.281 ms) : SELECT Address.addressId AS Address_addressId_0, Address.street AS Address_street_0, Address.number AS Address_number_0, Address.city AS Address_city_0, Address.zipcode AS Address_zipcode_0, Customer_1.customerId AS Customer_1_customerId_0, Customer_1.firstName AS Customer_1_firstName_0, Customer_1.lastName AS Customer_1_lastName_0, Orders_2.orderId AS Orders_2_orderId_0, Orders_2.date AS Orders_2_date_0, Orders_2.state AS Orders_2_state_0, Orders_2.customer AS Orders_2_customer_0_2 FROM Address LEFT OUTER JOIN Customer Customer_1 ON Customer_1.customerId = Address.addressId LEFT OUTER JOIN Orders Orders_2 ON Orders_2.orderId = Address.addressId
################### 1 1 "Musterstrasse"
################### 2 2 "Lieferstrasse"
But I expected to get something like:
- Code: Select all
################### -1 1 "Musterstrasse"
################### 1 2 "Lieferstrasse"
################### 2 3 "Anderelieferstrasse"
I don't quite get, what happens there and how to get the correct result.