CakePHP with underscore table ignore model
I have one metric table and another metric_levels table. In the Metric model, I have $ hasMany = 'MetricLevels', but everything inside the MetricLevels model is completely ignored.
But if I rename the model to "Metric" and I have $ useTable = 'metric_levels, it works fine. I've tried all combinations, but none works. I've tried plurals, singulars, underscores, nothing works. The model is simply ignored and it just takes the value from the database.
Any help is appreciated.
a source to share
It works now. This is how it looks:
// 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';
}
?>
$ order = 'upper_value DESC' is still being ignored, I don't know why. But at least now he is using the correct model.
a source to share
It's not terribly clear what your specific problem is, so just a few pointers:
- Model names are always singular
- HasMany MetricLevel
- Table names are plural and are translated to special patterns, underscores converted to CamelCase
- MetricLevel => metric_levels
- Even if you haven't created a model, Cake lets you use it and make it on the fly for you by calling table names using naming conventions
- If Cake is "ignoring" your model, it means it is creating another model on the fly, because you are not using the correct name for the model you really want.
- Looking at the generated SQL queries in
debug = 2
helps
http://book.cakephp.org/view/24/Model-and-Database-Conventions
a source to share