Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 631627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:59:11+00:00 2026-05-13T19:59:11+00:00

Now that I’ve read all the DQL docs I still have some doubts, I’m

  • 0

Now that I’ve read all the DQL docs I still have some doubts, I’m
trying to do some nested condictions in my DQL however playing around
with DQL I can’t seem to be able to archive them

To make myself more clear:

I have this DQL query

    $q = Doctrine_Query::create()
        ->select('c.nombre,c.webpage')
        ->addSelect('COUNT(m.marca_id) as total_marcas')
        ->from('Corporativos c')
        ->leftJoin('c.Marcas m')
        ->groupBy('c.corporativo_id')
        ->where('ISNULL(c.deleted_at)')
        ->orwhere('c.nombre LIKE :nombre', array(':nombre'=>'%'.$srch))
        ->orWhere('c.nombre LIKE :nombre', array(':nombre'=>'%'.$srch.'%'))
        ->orWhere('c.nombre LIKE :nombre', array(':nombre'=>$srch.'%'))
        ->orderBy('c.nombre ASC')
        ->limit(0,20);

now this generates the following MySQL query:

SELECT c.corporativo_id AS c__corporativo_id, c.nombre AS c__nombre,
c.webpage AS c__webpage, COUNT(m.marca_id) AS m__0 FROM corporativos c
LEFT JOIN marcas m ON c.corporativo_id = m.corporativo_id WHERE
(ISNULL(c.deleted_at) OR c.nombre LIKE :nombre OR c.nombre
LIKE :nombre OR c.nombre LIKE :nombre) GROUP BY c.corporativo_id ORDER
BY c.nombre ASC

However I’m getting a set of results where either deleted_at is null
or the other conditions is completed, I’d like to make the
isnull(deleted_at) obligatory, if we were talking in terms of SQL the
query would look like this:

SELECT c.corporativo_id AS c__corporativo_id, c.nombre AS c__nombre,
c.webpage AS c__webpage, COUNT(m.marca_id) AS m__0 FROM corporativos c
LEFT JOIN marcas m ON c.corporativo_id = m.corporativo_id WHERE
(ISNULL(c.deleted_at) AND (c.nombre LIKE :nombre OR c.nombre
LIKE :nombre OR c.nombre LIKE :nombre)) GROUP BY c.corporativo_id
ORDER BY c.nombre ASC

you can see that I just changed the first OR statement for an AND and
added a couple of parenthesis to group the LIKE conditions.

Is it posible to archivie this in DQL using the same ->where()
notation avoiding writing down the whole condition ?

thanks 🙂

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:59:12+00:00Added an answer on May 13, 2026 at 7:59 pm

    You can use Doctrine_Query::andWhere, but i think this will factor your statement the wrong way, so you could build your query like

    ->where('c.nombre LIKE :nombre', array(':nombre'=>'%'.$srch))
    ->andWhere('ISNULL(c.deleted_at)')
    ->orWhere('c.nombre LIKE :nombre', array(':nombre'=>'%'.$srch.'%'))
    ->andWhere('ISNULL(c.deleted_at)')
    ->orWhere('c.nombre LIKE :nombre', array(':nombre'=>$srch.'%'))
    ->andWhere('ISNULL(c.deleted_at)')
    

    which is kind of creepy.

    Here is another solution with modifies Doctrine to be capable of custom bracketing: http://danielfamily.com/techblog/?p=37

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now that I know C++ I want to get into desktop application that have
Now that I've finnaly moved to doing some development/support work for Windows 2008 I
Now that Rails 3 escapes all evaluated elements in views (good), but it is
I have a program that posts Datetime.Now(), but my coworkers computer's DateTime.Now() is off
I'm working on a project right now that is a shoutbox. Since I have
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
Now that the whole world is clambering to use SSL all the time (a
Now that I've upgraded to Rails 3, I'm trying to figure out the proper
Now that we have extension methods in C#, Is there any point left in
I have a url now that is accessed like: http://s1.name.com/healthApp I want it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.