in Education by
I have a n...n structure for two tables, makes and models. So far no problem. In a third table (products) like: id make_id model_id ... My problem is creating a view for products of one specifi make inside my ProductsController containing just that's make models: I thought this could work: var $uses = array('Make', 'Model'); $this->Make->id = 5; // My Make $this->Make->find(); // Returns only the make I want with it's Models (HABTM) $this->Model->find('list'); // Returns ALL models $this->Make->Model->find('list'); // Returns ALL models So, If I want to use the list to pass to my view to create radio buttons I will have to do a foreach() in my make array to find all models titles and create a new array and send to the view via $this->set(). $makeArray = $this->Make->find(); foreach ($makeArray['Model'] as $model) { $modelList[] = $model['title']; } $this->set('models', $models) Is there any easier way to get that list without stressing the make Array. It will be a commom task to develops such scenarios in my application(s). Thanks in advance for any hint! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here's my hint: Try getting your query written in regular SQL before trying to reconstruct using the Cake library. In essence you're doing a lot of extra work that the DB can do for you. Your approach (just for show - not good SQL): SELECT * FROM makes, models, products WHERE make_id = 5 You're not taking into consideration the relationships (unless Cake auto-magically understands the relationships of the tables) You're probably looking for something that joins these things together: SELECT models.title FROM models INNER JOIN products ON products.model_id = models.model_id AND products.make_id = 5 Hopefully this is a nudge in the right direction?

Related questions

0 votes
    5. Which key defines a relationship between two tables? (a) Primary key (b) Foreign key (b) Secondary key (d) ... Full form of RDBMS is Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    I have two different source structure tables, but I want to load into single target table? How do I go about it? Explain in detail through mapping flow....
asked Mar 28, 2021 by JackTerrance
0 votes
    How many tables may be included with a join? (a) One (b) Two (c) Three (d) All of the ... and Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    What is the maximum number of tables we can join in Tableau?...
asked Oct 29, 2020 in Technology by JackTerrance
0 votes
    1. Name the term which is used to join two separate arrays into a single array. 2.How are the following ... ii) primitive type data Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    A coin is tossed three times, where (i) E : head on third toss, F : heads on first two tosses (ii) E : at ... , F : at least one tail Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    I need more than the default diff! I have recently purchased "Beyond Compare" and I'd like to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    This one will take some explaining. What I've done is create a specific custom message queue in SQL ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This is a simple sort of crosstab query. I am having difficulty transferring my SQL knowledge to Linq and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how do I view all tables in SQL? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    I have three same source structure tables. But, I want to load into single target table. How do I do this? Explain in detail through mapping flow....
asked Mar 28, 2021 by JackTerrance
0 votes
    write algorithm and flowchart the inputs two numbers swaps these values without using third variable Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
0 votes
    A die is thrown three times, E : 4 appears on the third toss, F : 6 and 5 appears respectively on first two tosses Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
...