Issue of fetch_by_id_with_relation

Open discussion on QxOrm library

Issue of fetch_by_id_with_relation

Postby magicu » Mon Jan 30, 2012 7:18 am

This is my Card class:

class CPPSERVER_DLL_EXPORT Card
{
public:
Card() : id(0) {};
virtual ~Card() {};

int id;
CardTypePtr cardTypeX;
AdminPtr adminX;
QString no;
QString password;
bool is_used;
QDateTime create_date;
bool is_frozen;
};



This is my code:

CardPtr card(new Card());
card->id = 42;
qx::dao::fetch_by_id_with_relation("admin_id", card);


Before the fetch_by_id_with_relation function execute, The cardTypeX and adminX is null pointer like:

cardTypeX = {px=0x00000000 pn={...} }
adminX = {px=0x00000000 pn={...} }


After execution, it changed to:

cardTypeX = {px=0x02b9e878 pn={...} }
adminX = {px=0x02b828e8 pn={...} }

I think it should be:

cardTypeX = {px=0x00000000 pn={...} }
adminX = {px=0x02b828e8 pn={...} }

If it's was a bug?
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

Re: Issue of fetch_by_id_with_relation

Postby QxOrm admin » Mon Jan 30, 2012 8:58 am

Hi,

This is a normal behaviour of QxOrm library : lazy fetch vs eager fetch !
If QxOrm library can fetch the id of a relation without adding some SQL into the query, then your relation have only the ID fetched (lazy fetch).

So in your case, if you check your cardTypeX instance, you will see that the ID of the instance is fetched (lazy fetch), but not all other properties ;)
QxOrm admin
 


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron