简体   繁体   中英

Select Sections with Country Exception

I have a problem with a query:

I have a table with "sections" and another table with a Many to Many of SectionCountryException where only I have the values ​​of the countries do not want to appear.

Let me explain: I have many sections and I want some sections are not available in some countries.

Now I have this dql in a Section Table:

$dql = $this->createQuery('se')
->leftJoin('se.SectionCountryExceptions sce')
->whereNotIn('sce.value',$countryCode)
->orderBy....

but I know that's not right, but not how to do it ....

thanks

I answered myself ...

$dql = $this->createQuery('se')
                ->andWhereNotIn('se.id', $this->getExceptionsArray());

and the function:

private function getExceptionsArray()
        {
            $countryCode = sfConfig::get('app_default_country_code');
            $sectionCountryExceptions = Doctrine::getTable('SectionCountryException')->findByValue($countryCode);

            $exceptions = array();
            foreach ($sectionCountryExceptions as $exception)
            {
                $exceptions[] = $exception->getSection()->getId();
            }

            return $exceptions;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM