Wednesday, April 1, 2009

Re: How can I do this query in CakePHP 1.1.x

I don't know for CakePHP v1.1.x. However, if you use CakePHP v1.2.2 -

-- Here is the User Model
<?php
class User extends AppModel {
public $name='User';
public $hasOne=array('Page'=>array(
'foreignKey'=>false,
'type'=>'INNER',
'conditions'=>array('Page.user_id=User.id'),
)
);
};


-- And in the controller
<?php
/
*----------------------------------------------------------------------
* file: example_controller.php
*/
class ExampleController extends AppController{
public $name='Example';
public $uses=array();
public function index(){
$this->User=ClassRegistry::init('User');
$this->paginate=array('User'=>array('conditions'=> array (
'Page.status'=>1,
'User.username'=>'tehtreag',
),
'order'=>'User.username',
'fields'=>array(
'User.id',
'User.username',
'Page.id',
),
)
);
debug($this->paginate('User'));
$this->autoRender=false;
}

That should work.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: