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 8552515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:26:25+00:00 2026-06-11T14:26:25+00:00

I have a site developed in cakephp 2.0, I have some tables relationed here

  • 0

I have a site developed in cakephp 2.0, I have some tables relationed here is an example:
This is my relations:

ingredients (id,name) has many versions

ingredient_properties(id,property_id,version_id) belongs
to properties, versions

properties (id,name,value,group_id,unit_id) has many
ingredient_properties and belongs to groups,units

groups (id,name) has many properties

units (id,name) has many properties

versions (id,name,ingredient_id,active) has many ingredient_properties and belongs to ingredients.

I am in the ingredientController.php and I wanto to retrieve all this data where Version.active=1 and Version.ingredient_id=2.

This is my query:

$this->set(
        'ingredient',
        $this->Ingredient->Version->find('all', array(
            'recursive' => 2,
            'conditions' => array(
                'Version.active' => 1,
                'Version.ingredient_id' => 2
             )
        ))
);

I have many and many queries like this and I want to know if recursive 2 is the best way to retrieve all data of the table that I have explained or there is a better way most quickly (in terms of speed of query not to implement).
I hope that someone can help me to optimize my code because this query works but I don’t know if it is the better way to retrieve data of many tables relationed.

Thanks.

  • 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-06-11T14:26:26+00:00Added an answer on June 11, 2026 at 2:26 pm

    It is not the best way to use 'recursive' => 2 if you want to retrieve so much data. I believe it generates too many queries. Containable behaviour has the same drawback. The best way for me was to unbind models associations and construct table joins on the fly. You can look at an example here. But you need to know some SQL to understand what you do.

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

Sidebar

Related Questions

I have developed a site, which has some static pages. Like explore, home, feedback.
I have a site developed in CakePHP 2.0. I have a database with many
I have developed a web site that requires user registration and authentication for some
I have developed a site that has urls to other sites. I would like
I have a site developed in cakephp 2 and I want that into my
What I have is development version of intranet site developed with Django and some
I have a site developed with cakePHP. I have it under source control with
I have a site developed with django at www.example.com I want that django insert/serve
I have a site which has been developed completely in flash. Now the site
I have a site developed in cakephp 2.0, I want to make a relation

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.