I've now managed to get it to work doing the following:

Here is how it is:

// metric.php
var $hasMany = 'MetricLevel'

// metric_level.php
<?php
    class MetricLevel extends AppModel {
        var $name = 'MetricLevel';
    var $useTable = 'metric_levels';
    var $order = 'upper_value DESC';
    var $belongsTo = 'colour';
    }
?>

The $order = 'upper_value DESC' is still being ignored, I don't know
why. But at least it's now using the correct model.


On Apr 20, 8:23 am, xiaohouzi79 <[email protected]> wrote:
> Hi John, thanks for the reply.
>
> It's still not working:
>
> In the /app/models folder I have two files:
>
> Metric.php
>
> <?php
> class Metric extends AppModel {
>     var $name = 'Metric';
>         var $recursive = 2;
>     var $hasMany = 'MetricLevel';}
>
> ?>
>
> MetricLevel.php
> <?php
> class MetricLevel extends AppModel {
>     var $name = 'MetricLevel';
>         var $useTable = 'metric_levels';
>         var $order = 'upper_value DESC';}
>
> ?>
>
> I remove the cache files each time to make sure it's not using a
> cached version. If I change either $useTable or $order it is
> completely ignored, so I know it's not being picked up. But, if I
> rename the MetricLevel.php file to a single name such as blah.php and
> set Metric.php $hasMany = 'blah' and then $useTable = 'metric_levels'
> it works. So for some reason when I set the name to the name of an
> actual table it seems to be creating it's own model and ignoring mine?
>
> Thanks,
> Tim.
>
> On Apr 19, 4:57 pm, John Andersen <[email protected]> wrote:
>
>
>
> > You model should be in singular form, which mean that is should be
> > named "MetricLevel" not "MetricLevels", then CakePHP will ensure that
> > the correct table will be used.
> > Enjoy,
> >    John
>
> > On Apr 19, 9:08 am, xiaohouzi79 <[email protected]> wrote:
>
> > > Hi,
>
> > > I have one table metrics and another table metric_levels. In the
> > > Metric model I have $hasMany = 'MetricLevels' but anything inside the
> > > MetricLevels model is totally ignored.
>
> > > But, if I rename the model to 'Metric' and have $useTable =
> > > 'metric_levels' it works fine. I've tried all combinations, but none
> > > seem to work. I've tried plurals, singulars, underscores, nothing
> > > seems to work. The model is simply ignored and it just takes the value
> > > from the database.
>
> > > Any help is appreciated.
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers 
> > > with their CakePHP related questions.
>
> > > 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 
> > > athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
> > with their CakePHP related questions.
>
> > 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 
> > athttp://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to