Hey Paul,
Thanks for the solution, I would have never figured this
out.....could u explain what u are doing in
$this->Invoice->bindModel(
> array(
> 'belongsTo' => array(
> 'Mandal'=>array(),
> 'District'=>array('foreignKey'=>false, 'conditions'=>array
> ('Mandal.district_id = District.id'))
> )
> ),
> false
> );
in a little more detail.....i understand u are creating a new
relation, but why is 'Mandal'=>array() ???
THANQ ONCE AGAIN......:)
On Jan 20, 2:27 pm, WebbedIT <[email protected]> wrote:
> Forrestgump,
>
> CakePHP does not join tables on deep belongsTo associations, even if
> you increase recursive. This effects you as the relationship from
> your Invoice to District models is as follows:
>
> Invoice belongsTo Mandal -> Mandal belongsTo District
>
> It took me over a week to solve this solution as I was wanting to use
> paginate and wanted to order the results by data from a table 2
> belongsTo relations away. The answer is to force a join from Invoice
> to District as follows:
>
> $this->Invoice->unbindModel(
> array(
> 'belongsTo' => array('Mandal'),
> ),
> false
> );
> $this->Invoice->Mandal->unbindModel(
> array(
> 'belongsTo' => array('District')
> ),
> false
> );
> $this->Invoice->bindModel(
> array(
> 'belongsTo' => array(
> 'Mandal'=>array(),
> 'District'=>array('foreignKey'=>false, 'conditions'=>array
> ('Mandal.district_id = District.id'))
> )
> ),
> false
> );
>
> Essentially you are unbinding any existing associations to the models
> in question, then creating a new association. By setting foreignKey
> to false you can then set your own custom condition which will allow
> you to join Invoice direct to District.
>
> Because I was using paginate which runs more than one query, I added a
> false parameter to each bindModel() and unbindModel() so the binds
> would not reset after the first query. If just running a find() then
> you can leave these as the default true.
>
> Also if you are not wanting to use paginate and sort columns, you can
> look at using the containable behaviour which will also pull the data
> out for you, but stores the data in a different array format to the
> above option.
>
> Regards,
>
> Paul.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---