On 8/23/07, Chris Hartjes <[EMAIL PROTECTED]> wrote:
> > Yes. And also need different condition for each one. Is that possible ?
> >
>
> Well, how would you do this if you weren't using CakePHP. I think
> that will answer your question.
I would loop for each row of first query and query the other database.
>
> (I'll give you a hint - look into how to create different database
> configurations and how to tell your model to use the non-default one)
Actually I have done it and it working great with hasOne association.
Even I can do a sort of it. The only drawback is I cannot have query
condition for both models. I can only do that in main model.
To make it clear I better write down my code :)
-------------------------------------------------------------------
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeuser',
'password' => 'mycakepass',
'database' => 'cakedb',
'prefix' => ''
);
var $mssqlconn = array(
'driver' => 'mssql',
'persistent' => false,
'host' => 'localhost',
'login' => 'sa',
'password' => 'somepassword',
'database' => 'CustomerDB',
'prefix' => ''
);
}
-------------------------------------------------------------------
-------------------------------------------------------------------
Model : Customer
-------------------------------------------------------------------
<?php
class Customer extends AppModel
{
var $name = 'Customer';
var $useTable = 'Customers';
var $useDbConfig = 'mssqlconn';
var $belongsTo = array(
'Sales' => array('className' => 'Sales',
'foreignKey' => 'sales_id',
'conditions' => '',
'fields' => '',
'order' => '',
'counterCache' => ''),
);
}
?>
-------------------------------------------------------------------
-------------------------------------------------------------------
Model : Sales
-------------------------------------------------------------------
<?php
class Sales extends AppModel
{
var $name = 'Sales';
var $hasOne = array(
'Customer' => array('className' => 'Customer',
'foreignKey' => 'customer_id',
'conditions' => '',
'fields' => '',
'order' => '',
'counterCache' => ''),
);
}
?>
-------------------------------------------------------------------
And then I have them paginated in my view. With model condition like below :
================================
$conditions=> array('Sales.id'=>'123')
$this->paginate('Sales', $conditions).
================================
it is woking fine.
But when I need to have conditions for both models.
===================================================
$conditions=>array('Sales.id'=>'123', 'Customer.sales_id'=>'123').
$this->paginate('Sales', $conditions).
===================================================
It generates error . Then I take a look at the debug sql output. And
it seems that cakephp join Sales & Customer during sql call instead of
separating them for each queries which it does for 'pagination'
process.
I still try to get better understanding with cakephp core lib code for
pagination. But meanwhile I try to post it here if somebody has any
experience with this kind of 'problem', has resolved it and can help
me with that :)
Hope that I make myself clear enough :P
>
> --
> Chris Hartjes
> Senior Developer
> Cake Development Corporation
>
Best Regards,
Feris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---