Jan Kellermann | werk21 writes:
> Hi,
Hi!
> When we use OR for the outer group we get a result. Beside that the
> result is not what we really need ("AND") shows the result that every
> single constraint-group is correct.
>
> Beside 2nd: When we use OR for the outer group, articles may be multiple
> in result - that is unexpected.
>
> Can anyone please give us a hint for getting the correct result. Maybe
> query_builder is the wrong tool?
Query Builder can not do correct joins and this is a problem in your case.
Workaround is (unfortunately) creating two QB instances and executing
two queries.
$qb = new midgard_query_builder("midgard_parameter");
$qb->begin_group('AND');
$qb->begin_group('AND');
$qb->add_constraint('parameter.domain', '=', 'domain1');
$qb->add_constraint('parameter.name', '=', 'name1');
$qb->end_group();
$qb->begin_group('AND');
$qb->add_constraint('parameter.domain', '=', 'domain1');
$qb->add_constraint('parameter.name', '=', 'name2');
$qb->end_group();
$qb->begin_group('AND');
$qb->add_constraint('parameter.domain', '=', 'domain2');
$qb->add_constraint('parameter.name', '=', 'name1');
$qb->end_group();
$qb->end_group();
$ret = $qb->execute();
foreach($ret as $parameter)
{
$parentguids[] = $paremeter->parentguid;
}
if(empty($parentguids))
{
/* handle empty result case*/
}
$qb_a = new midgard_query_builder("midgard_article");
$qb_a->add_constraint("guid", "IN", $parentguids);
$articles = $qb->execute();
Point here is to fetch all parameters which holds required domain and name.
Later on we use parentguid property as constraint to limit fetched
article records.
Piotras
_______________________________________________
user mailing list
[email protected]
http://lists.midgard-project.org/mailman/listinfo/user