Tuesday, March 29, 2011

Re: paginate conditions hasMany question

Try following

$this->Member->bindModel(array('hasOne' => array('Payment')),
false);
$this->Member->unbindModel(array('hasMany' =>
array('Payment')), false);

$this->paginate['Member']['contain'] = array('Payment') //
make sure Member Model actAs Containable

$results = $this->paginate('Member', array('Payment.status' =>
'1'));

Thanks,
hunny.


On Mar 29, 4:11 pm, heohni <heidi.anselstet...@consultingteam.de>
wrote:
> Hi,
>
> I struggle...
>
> I have the following statement:
> $list = $this->paginate('Member');
> Which returns an array (in short) like this:
>
> Array
> (
>     [0] => Array
>         (
>             [Member] => Array
>                 (
>                     [id] => 5
>                 )
>
>             [Payment] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 2520
>                             [member_id] => 5
>
> The debug mode shows me that there are 2 mysql statements performed.
> One to get the members and one to get the payments.
>
> The model is that members hasMany paymennts.
> And payment belongTo a member.
>
> I dont get it now, how I can set conditions regarding the payment
> select?
> For example I just want to select members where the payment status =
> 1.

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: