You could try looking at the linkable behavior:
http://rafaelbandeira3.wordpress.com/2008/11/16/linkable-behavior-taking-it-easy-in-your-db/
It looks promising, but I haven't used it (yet) and can't guarantee it
will handle your use case.
If not, you could re-bind manually to the deeper associations - I used
this technique on a project a few months ago and it worked fine.
$this->ModelA->bindModel(array('belongsTo' => array(
'ModelCTemp' => array(
'className' => 'ModelC',
'foreignKey' => false,
'fields' => array('bacon'),
'conditions' => 'ModelCTemp.id = ModelB.foreign_id'
),
'ModelDTemp' => array(
'className' => 'ModelD',
'foreignKey' => false,
'fields' => array('eggs'),
'conditions' => 'ModelDTemp.id = ModelC.foreign_id'
)
)));
$results = $this->ModelA->find('all', array(
'order' => 'ModelCTemp.bacon ASC, ModelDTemp.eggs DESC'
));
(The 'Temp' prefix is to avoid the other link results from overlapping
- I can't remember why this is an issue but it was at the time)
hth
grigri
On Jan 13, 3:01 pm, the_woodsman wrote:
> Hi Bakers,
>
> These are my model relations, in general terms:
>
> [ModelA] belongsTo [ModelB] belongsTo [ModelC] belongsTo [ModelD]
>
> I'm calling ModelA->contain(...)
>
> In my contain I'm successfully retrieving fields all the way down to
> Model D.
>
> However, when it comes to ordering, I get errors when trying to order
> by fields in model C or D.
>
> Unknown column 'ModelC.field' in 'order clause'
>
> From the SQL, it's clear the problem is that models C and D are
> accessed via different,
> individual queries per model (Select `ModelC`.field FROM `ModelC`),
> and re-integrated into the results set, whilst the ordering statements
> are of course in the initial query.
>
> I'm around 1.2 RC2.
>
> Is this a known issue? Are there any solutions/work arounds? I really
> don't want to manually re-sort my data :(
>
> Thanks,
>
> Woody
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---