Complex Fetching

Open discussion on QxOrm library

Complex Fetching

Postby Kasuax » Thu Jun 30, 2016 9:19 pm

I'm having difficulty performing the following.

  1. Populate Project Hierarchy into Database
  2. Fetch Project Hierarchy from database
  3. Dump Database records
  4. Re-save Project Hierarchy to Database
The issue I was having earlier was that while I can successfully save my Project Hierarchy I cannot read it all back at once. I knew it was possible but something was eluding me. Originally I was performing a fetch_all_with_all_relation which was stupid because it only maintained 1 level of relationships. Then I thought, I'll just add after_fetch logic to each sub object so that it can go fetch for it's dependencies. Well that was stupid too because I ended up in a circular loop of never-ending fetches.

My new strategy is to go through and manually define my relationships for each save and fetch that I want to do at my top most project level.

Example Code
Code: Select all
    QStringList r;
    r << "Coefficients->Breakpoints"
      << "SystemParams"
      << "UserParams"
      << "DataTables"
      << "ChannelCategories"
      << "InstrumentationTypes"
      << "Triggers"
      << "SimDataIndex"
      << "FacilityChannels"
      << "ChannelLimits"
      << "LimitActions"
      << "ComponentSpecifications->PropertySchemaList->*"
      << "ComponentSpecifications->SubComponentSpecs"
      << "Components->SubComponents"
      << "Components->Properties"
      << "Components->ComponentChannels->Properties"


With that mapping more rigidly defined I can start to perform fetch_by_id_with_relation. This seemed to be working way better. The XML I dumped out was also grossly larger though which concerned me. Low and behold I cannot recommit the xml to the db because my foreign key relationships keep squawking that their prerequisite objects didn't get inserted first. I thought that this method of defining the relationship map would allow me to specify the ordering of what goes first. What happened?

What does save_all_with_recursion really do? does it just follow all of the 1-n relationships it can? How does it know to avoid circular logic if not? So many questions...

Thanks in advance!
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: Complex Fetching

Postby qxorm » Fri Jul 01, 2016 8:09 am

Hello,

My new strategy is to go through and manually define my relationships for each save and fetch that I want to do at my top most project level.
...
With that mapping more rigidly defined I can start to perform fetch_by_id_with_relation. This seemed to be working way better.

Yes, this is the way to select and fetch several levels of relationships.

I cannot recommit the xml to the db because my foreign key relationships keep squawking that their prerequisite objects didn't get inserted first.

What is your code to save all items in database ?
What is exactly the error message ?

How does it know to avoid circular logic if not?

After fetching several levels of relationships, QxOrm doesn't generate circular dependencies ==> so I think there is no problem here.

What does save_all_with_recursion really do? does it just follow all of the 1-n relationships it can?

Yes, this function tries to save all relationships (all levels) it found.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Complex Fetching

Postby Kasuax » Fri Jul 01, 2016 3:56 pm

Error message below.

Code: Select all
ERROR:  insert or update on table "t_componentinstance" violates foreign key constraint "fk_t_componentinstance_componentspec"
DETAIL:  Key (componentspec)=(9) is not present in table "t_componentspec".
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: Complex Fetching

Postby Kasuax » Fri Jul 01, 2016 4:43 pm

So can you not do a save_with_relation and have it blast out more than 1 level of relationships?
Are you forced to use save_with_relation_recursive or manually define all of the saving steps yourself?
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: Complex Fetching

Postby qxorm » Mon Jul 04, 2016 7:53 am

So can you not do a save_with_relation and have it blast out more than 1 level of relationships?

No : qx::dao::save_with_relation() and qx::dao::save_with_all_relation() functions are not able to save more than 1 level of relationship.

Are you forced to use save_with_relation_recursive or manually define all of the saving steps yourself?

Yes : qx::dao::save_with_relation_recursive() function saves all levels of relationships it can find.

I think that in your case you should call yourself all saving functions manually.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron