Have you tried just putting the conditions in the paginate call?

class HotelsController extends AppController {
  var $paginate = array(
    'Hotel' => array(
      'limit' => 10,
      'contain' => array(
        'Hotelmaster', ...
      )
    )
  );

  function search() {
    // Example conditions
    $conditions = array(
      'Hotelmaster.deleted' => 0,
      'Hotelmaster.name LIKE ?' => array('%novo%')
    );
    $results = $this->paginate('Hotel', $conditions);
  }
}

Always remember that the `conditions` key in a relation is the join
condition (the bit in the 'ON (...)' clause), it doesn't affect the
result set.

Contrast this (conditions in the relation):

SELECT Hotel.*, Hotelmaster.* FROM hotels AS Hotel LEFT JOIN
hotelmasters AS Hotelmaster ON (Hotelmaster.id=Hotel.hotelmaster_id
AND Hotelmaster.deleted=0)

with this (conditions in the find):

SELECT Hotel.*, Hotelmaster.* FROM hotels AS Hotel LEFT JOIN
hotelmasters AS Hotelmaster ON (Hotelmaster.id=Hotel.hotelmaster_id)
WHERE Hotelmaster.deleted=0

See the difference? (Run the queries directly in phpMyAdmin to see)

If you're having trouble, first unbind everything you don't need.
Contain only the important models, make it work, then add the others
back one by one.

Also, please paste the SQL logs you're getting. It makes diagnosing
the problem a lot easier :)

hth
grigri

On Nov 25, 1:42 pm, "Liebermann, Anja Carolin"
<[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I am trying to program a search with contain since nearly a week now and
> I still don't get it right.
>
> What I want to do:
>
> Hotel belongsto Hotelmaster (Hotel is a kind of blueprint of
> Hotelmaster)
> I search for Hotel and want only to find datasets where the related
> Hotelmaster fulfills certain conditions.
> To make it worse the result should be paginated.
>
> What I have now in my hotels_controller.php is:
>
> $this->paginate['Hotel'] = array(
>                         'limit' => 10,
>                         'order' => array ('Hotel.name' => 'asc',
> 'Saison.id' => 'desc'),
>                         'url' => $paginator_params,
>                         'condition' => $paramhotel,
>                 'contain'=> array(
>                     'Hotelmaster'=> array(   'conditions'=>
> $parammaster,
>
> 'Praefix'=>array('fields'=>array('Praefix.name'))),
>                     'Town'=> array('fields'=>
> array('Town.name','Town.id')),
>                     'Praefix', //and some more models of no interest
>                     'User'=> array('fields'=> 'User.name'))
>                 );
>
> $parammaster is an array depending on my search criteria and can look
> like (simple example):
> Array
> (
>     [Hotelmaster.deleted =] => 0
>     [Hotelmaster.name LIKE] => "%Novo%"
> )
>
> I am not sure if the syntax of my conditions is correct. In some
> examples I find on the net the syntax of the conditions within the
> contain statement differ from the "normal" conditions. And to make
> things worse the whole thing is in a "paginate" and not a "find".
>
> At the moment any search critera have no effect on my search. When I
> change the search criteria to something like this
> (
>     Hotelmaster.deleted = 0
>     Hotelmaster.name LIKE "%Novo%"
> )
>
> I get 5 search results when having only 2 datasets in my database. Very
> weird.
>
> What would be the correct syntax for my $parammaster searchconditions?
>
> Thank you for any help
>
> Anja
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to