From 516a084d7de6b23f2e2e5c056779225ec3e4f6c2 Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 16 Apr 2009 12:48:54 +0000 Subject: [PATCH] In oils_cstore.c: fix autojoin, i.e. the facility for constructing a join when the JSON query doesn't specify the columns involved. When looking up a foreign key linkage in the IDL, ignore the parent table's end of the link (where reltype = "has_many"), because the parent doesn't know the name of the column at the other end. Now an autojoin can work regardless of which table is subordinate to which. git-svn-id: svn://svn.open-ils.org/ILS/trunk@12886 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_cstore.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 7f4ab4b3aa..8a1778e355 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -2247,7 +2247,6 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) { jsonIteratorFree(search_itr); return NULL; } - field = field; } else if (!field && !fkey) { osrfHash* _links = oilsIDL_links( leftclass ); @@ -2260,10 +2259,15 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) { const char* other_class = osrfHashGet( curr_link, "class" ); if( other_class && !strcmp( other_class, class ) ) { - // Found a link between the classes - fkey = osrfHashIteratorKey( itr ); - field = osrfHashGet( curr_link, "key" ); - break; + // In the IDL, the parent class doesn't know then names of the child + // columns that are pointing to it, so don't use that end of the link + const char* reltype = osrfHashGet( curr_link, "reltype" ); + if( reltype && strcmp( reltype, "has_many" ) ) { + // Found a link between the classes + fkey = osrfHashIteratorKey( itr ); + field = osrfHashGet( curr_link, "key" ); + break; + } } } osrfHashIteratorFree( itr ); @@ -2280,10 +2284,15 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) { const char* other_class = osrfHashGet( curr_link, "class" ); if( other_class && !strcmp( other_class, leftclass ) ) { - // Found a link between the classes - fkey = osrfHashIteratorKey( itr ); - field = osrfHashGet( curr_link, "key" ); - break; + // In the IDL, the parent class doesn't know then names of the child + // columns that are pointing to it, so don't use that end of the link + const char* reltype = osrfHashGet( curr_link, "reltype" ); + if( reltype && strcmp( reltype, "has_many" ) ) { + // Found a link between the classes + field = osrfHashIteratorKey( itr ); + fkey = osrfHashGet( curr_link, "key" ); + break; + } } } osrfHashIteratorFree( itr ); -- 2.11.0