[odb-users] Combining views queries conditions

Даниил Савченко cfdx at list.ru
Thu Nov 12 08:55:11 EST 2015


Good day.
Could you please tell me if it is a correct way to use ODB:
 

#pragma db object
class Object…;
 
#pragma db view object(Object)
class View…;
 
void f( const query<Object>& q )  {
   auto res = db->query<View>( q );
}
 
I have tried it and it looks like it works. But is it a hack?
In more complicated cases:
#pragma db view object(Object1) object(Object2:...)
class View2…;
 
void f( const query<Object1>& q )  {
   auto res = db->query<View2>( q );
}
OR
void f( const query<Object1>& q1, const query<Object2>& q2 )  {
   auto res = db->query<View2>( q1 && q2 );
}
OR
void f( const query<Object1>& q1, const query<Object2>& q2 )  {
  query<Object1> qx = q1 && q2; // strange, but works!
   auto res = db->query<View2>( qx );
}
And the most crazy use case:
void f( const query<View1>& q )  {
   // works if View1 query condition uses a subset of objects, used in View2
   auto res = db->query<View2>( q );
}
 
Is combining of condition for different Object and Views queries a correct way of creation of condition for Views. And if “yes”, what are the formal limits of applicability.
I understand that it is possible to set conditions right in terms of the View fields, but I want to encapsulate creation subconditions in different parts of application, and reuse these parts in different places where different Views are used. Or maybe there exist recommended way (some best practices) to do this.
Daniil Savchenko

С уважением,
Даниил И. Савченко



More information about the odb-users mailing list