public function isManyToMany($deep = true)
    {
        if (null === $this->isM2M) {
            switch (true) {
                // user hinted that this is a m2m table or not
                case in_array($m2m = $this->parseComment('m2m'), array('true', 'false')):
                    $this->isM2M = 'true' === $m2m ? true : false;
                    $this->getDocument()->addLog(sprintf('  * %s: M2M from comment "%s"', $this->getRawTableName(), var_export($this->isM2M, true)));
                    break;

                // contains 2 foreign keys
                case (2 !== count($fkeys = $this->getForeignKeys())):
                    $this->isM2M = false;
                    $this->getDocument()->addLog(sprintf('  * %s: M2M set to false, foreign keys not equal to 2', $this->getRawTableName()));
                    break;

                // different foreign tables
                case ($fkeys[0]->getReferencedTable()->getId() === $fkeys[1]->getReferencedTable()->getId()):
                    $this->isM2M = false;
                    $this->getDocument()->addLog(sprintf('  * %s: M2M set to false, foreign table is same', $this->getRawTableName()));
                    break;

                // foreign tables is not many to many
                case $deep && $fkeys[0]->getReferencedTable()->isManyToMany(false):
                case $deep && $fkeys[1]->getReferencedTable()->isManyToMany(false):
                    $this->isM2M = false;
                    $this->getDocument()->addLog(sprintf('  * %s: M2M set to false, foreign table is M2M', $this->getRawTableName()));
                    break;

                // has more columns than id + 2 x key columnns, is not many to many
                case (count($this->getColumns()) >= 3):
                    $this->isM2M = false;
                    $this->getDocument()->addLog(sprintf('  * %s: M2M set to false, columns are 3 or more', $this->getRawTableName()));
                    break;

                default:
                    $this->isM2M = true;
                    $this->getDocument()->addLog(sprintf('  * %s: is M2M', $this->getRawTableName()));
                    break;
            }
        }

        return $this->isM2M;
    }