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

  • Home
  • SEARCH
  • 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 7697703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:32+00:00 2026-05-31T22:04:32+00:00

how do I build a find() query in cakePHP using these conditions: Find where

  • 0

how do I build a find() query in cakePHP using these conditions:

Find where 
MyModel.x = 1 and MyModel.y = 2 OR 
MyModel.x = 1 and MyModel.y value does not exist (or is equal to empty string)

Can somebody tell me how I can go about building such find query?

  • 1 1 Answer
  • 0 Views
  • 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-31T22:04:33+00:00Added an answer on May 31, 2026 at 10:04 pm

    I’m gonna give you some pointers, but you need to try to do this as it’s very basic and it’s always good to practice.

    A basic find in cake is in the form of

    $this->ModelName->find('all');
    

    This in its default form does a SELECT * from model_names (convention is to have singular ModelName for plural table name – model_names)

    To add conditions:

    $this->ModelName->find('all', array('conditions' => array('ModelName.x' => 1));
    

    To add AND conditions

    $this->ModelName->find('all', array('conditions' => array(
       'ModelName.x' => 1, 'ModelName.y' => 2
    ));
    

    To add OR conditions

    $this->ModelName->find('all', array('conditions' => array(
       'OR' => array(
          'ModelName.x' => 1, 'ModelName.y' => 2
        )
    ));
    

    To combine both

    $this->ModelName->find('all', array('conditions' => array(
       'ModelName.y is not' => null,
       'OR' => array(
          'ModelName.x' => 1, 'ModelName.y' => 2
        )
    ));
    
    // where y is not null and (x = 1 or y = 2) 
    

    http://book.cakephp.org/1.3/view/1030/Complex-Find-Conditions

    (btw I’m sure there will be users giving you the exact answers, so just take my answer for your reference 🙂 )

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

Sidebar

Related Questions

I am trying to find the best way to build a dynamic linq query
After following these steps: http://developers.facebook.com/docs/mobile/android/build/ I find that everything goes well, but when I
I'm getting the build error 'error VCBLD0007: Could not find project configuration RELEASE|X64 to
I'm trying to build a rather specific query to find a set of user_ids
I'm trying to build a Hibernate Criteria query to find entities that have a
I am trying to build a .NET web application using SQL to query AS400
Can someone suggest me how to build up the following query using JPA Criteria
Trying to figure out how to build a query in CakePHP where I can
Using the Kohana query builder, is it possible to build my query piece by
I'm looking for the name of the PHP function to build a query string

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.