Checking Model Relationships in CakePHP

Is there a way to check the relationship of a CakePHP model?

One model saves twice on the table, and I really suspect there is something wrong with my relationship. The problem is I have a lot of tables, so this is really a pain. I am wondering if there is a more confident and simpler way to do this, perhaps automatically? Thanks in advance!

+2


source to share


1 answer


You can use var_dump

or print_r

to see how your models look. If you want to quickly do this for all models, change AppModel

so that it resets the structure when each model is loaded.



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);
    }
}

      

+2


source







All Articles