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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:05:05+00:00 2026-05-18T02:05:05+00:00

Like the example in cakephp manual, http://book.cakephp.org/view/1323/Containable#Containing-deeper-associations-1325 , i need to fetch data from

  • 0

Like the example in cakephp manual, http://book.cakephp.org/view/1323/Containable#Containing-deeper-associations-1325, i need to fetch data from a model through a condition on its association model.

I have:

Model Language:

class Language extends AppModel {

    var $name = 'Language';
    var $actsAs = array('Containable');

        var $hasMany = array(
        'LanguageTranslation' => array(
            'className' => 'LanguageTranslation',
            'foreignKey' => 'language_id'
        )
    );

}

And the association, ModelTranslation

class LanguageTranslation extends AppModel {

    var $name = 'LanguageTranslation';

    var $belongsTo = array(
        'Language'
    );
}

when i do:

$language_array = $this->controller->Language->find('all', array(
            'contain' => "LanguageTranslation.id = 1" 
        ));

i receive all the languages, not only one (because id in LanguageTranslation is unique). The result need to be one!

SO, with

debug($language_array);

result is:

Array
(
    [0] => Array
        (
            [Language] => Array
                (
                    [id] => 1
                    [code] => it
                    [locale] => ita
                )

            [LanguageTranslation] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [language_id] => 1
                            [language] => italiano
                        )

                )

        )

    [1] => Array
        (
            [Language] => Array
                (
                    [id] => 2
                    [code] => en
                    [locale] => eng
                )

            [LanguageTranslation] => Array
                (
                )

        )

    [2] => Array
        (
            [Language] => Array
                (
                    [id] => 3
                    [code] => de
                    [locale] => ger
                )

            [LanguageTranslation] => Array
                (
                )

        )
)

Why i don’t catch only the Language with id = 1?

  • 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-18T02:05:06+00:00Added an answer on May 18, 2026 at 2:05 am

    The conditions in containable apply only to the models inside the containment. Because the main query doesn’t have any conditions it fetches every row in the table. In general you don’t use containable to restrict the main query but to limit the way the query goes through the containment tree (very handy when you need to go through 3-4 levels of recursiveness where the results can get quite bloated if not contained).

    In this case in particular if you are trying to get the data of a certain Language/LanguageTranslation pair, you can just pull the data from the LanguageTranslation model.

    $this->Language->LanguageTranslation->find( 
        'first',
        array( 
            'conditions' => array( 'LanguageTranslation.id' => 1 ),
            'recursive'  => 1
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use CakePHP Paging I get an url like this: http://example.com/php/page:2 What do
I usually do something like the example below when I need to return error
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
I have a query using the Containable behavior in cakephp that looks like this
I am using only slug to identify a page on the website, like: example.tld/view/this-fancy-slug
I have a Struts + Velocity structure like for example, a Person class, whose
I'd like a simple example of exporting a function from a C++ Windows DLL.
Many C++ books contain example code like this... std::cout << Test line << std::endl;
I have a custom c# type like (just an example): public class MyVector {
What does it mean to call a class like this: class Example { public:

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.