Reputation: 241
Is there a way to check CakePHP's model relationships?
One model is saving twice on a table and I really suspect there's something wrong with my relationships. Problem is I have a lot of tables so it's really a pain. I'm wondering if there's a more sure and easy way of doing this maybe automatically? Thanks in advance!
Upvotes: 2
Views: 564
Reputation: 83279
You can use var_dump
or print_r
to see what your models look like. If you want to quickly do it for all models, modify AppModel
to have it dump the structure when each model loads.
class AppModel extends Model {
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->log("Model [{$this->name}] belongsTo = " . print_r($this->belongsTo, true), LOG_DEBUG);
$this->log("Model [{$this->name}] hasOne = " . print_r($this->hasOne, true), LOG_DEBUG);
$this->log("Model [{$this->name}] hasMany = " . print_r($this->hasMany, true), LOG_DEBUG);
$this->log("Model [{$this->name}] hasAndBelongsToMany = " . print_r($this->hasAndBelongsToMany, true), LOG_DEBUG);
}
}
Upvotes: 2