Hi Johan, I agree with you, it should not return an SQL error. Strange...
Anyway, your solution doesn't work. I tried it and what it does is that it removes the index "language_id" in the returned array, when "language_id" is different than 2, BUT it doesn't filter the pagination. You know what I mean? If I could stick the Language table to the Result table, using the Nationality table as the relation table, the problem should be solved. But I don't know how to do that. Thanks! On Jun 22, 12:27 pm, Johan <[email protected]> wrote: > That's weird because that code should throw an SQL error. When you > paginate or do a find, CakePHP will only use on the primary query the > immediate hasOne/belongsTo associations (in this case Result -> Test), > so your code should generate something similar to this query: > > SELECT * FROM results Result LEFT JOIN tests Test ON Test.id = > Result.test_id WHERE Nationality.language_id LIKE '2'; > > If that query would work (which doesn't), it would generate an > additional query for each row fetching the required data from the > table nationalities. > So the problem is that you are setting the conditions on the wrong > place. This code should work correctly: > > $this->paginate = array( > 'limit' => 20, > 'contain' => array( > 'Test' => array( > 'Nationality' => array( > 'fields' => array('language_id'), > 'conditions' => array('Nationality.language_id LIKE ?' => > 2) // Do you really need to use LIKE instead of equals? > ) > ) > ) > ); > > If you require the Nationality to be an inner join, you may need to > rebind the models on runtime or add an explicit inner > join:http://book.cakephp.org/view/1047/Joining-tables > > Cheers, > - Johan > > On Jun 20, 4:49 pm, thomaus <[email protected]> wrote: > > > > > > > > > Thanks for helping. > > > I just tried and that is very strange. I don't get anymore SQL error > > but it doesn't work. I mean the filtering returns an empty array, > > while it should not. I checked and I'm 100% sure there should be some > > output after the filtering. > > > On Jun 20, 11:12 am, Tilen Majerle <[email protected]> wrote: > > > > emm...try this > > > > $filter = array(); > > > $filter['Nationality.language_id LIKE'] = 2; > > > > -- > > > Lep pozdrav, Tilen Majerlehttp://majerle.eu > > > > 2011/6/20 thomaus <[email protected]> > > > > > Nobody no clue? > > > > > On Jun 17, 5:43 pm, thomaus <[email protected]> wrote: > > > > > Hi there, > > > > > > I am doing2ndorderpaginationusing Containable. It is working fine > > > > > but when I try to paginate with a2ndorderfilter, it doesn't work > > > > > anymore. > > > > > > Here are my models relations : > > > > > > "Result" belongs to "Test" > > > > > "Test" belongs to "Nationality" > > > > > > Here is my code : > > > > > > $this->Result->recursive = 2; > > > > > $this->Result->Behaviors->attach('Containable'); > > > > > > $this->paginate = array( > > > > > 'limit' => 20, > > > > > 'contain' => array( > > > > > 'Test' => array( > > > > > 'Nationality' => array('fields' => array('language_id')) > > > > > ))); > > > > > > $filter = array(); > > > > > $filter['Test.Nationality.language_id LIKE'] = 2; > > > > > > $results = $this->paginate(null, $filter); > > > > > > and I get this error: > > > > > > SQL Error: 1054: Unknown column 'Test.Nationality.language_id' > > > > > > If I empty the filter array, I can access $result['Test'] > > > > > ['Nationality']['language_id'] from my view without any problem so the > > > > >paginationis working fine BUT the filtering is NOT. Why? > > > > > -- > > > > Our newest site for the community: CakePHP Video Tutorials > > > >http://tv.cakephp.org > > > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp > > > > others with their CakePHP related questions. > > > > > To unsubscribe from this group, send email to > > > > [email protected] For more options, visit this group > > > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
