在schema.xml中自动生成isCrossRef

时间:2013-07-05 10:12:53

标签: propel

我目前正在开发一个带有silex,propel和twig的模块化站点。 我打算在它上面创建一个安装程序项目,这样我就可以根据我的“核心”项目轻松创建新项目。

我的数据库有一些多对多表,需要我的schema.xml中的isCrossRef属性。逆向工程时我的MySql数据库Propel无法确定哪些表是crossRef。我明白了,但现在我想知道我是否可以改变schema.xml的生成。

Lets说如果我向需要这个isCrossRef属性的表添加注释,那么在Propel源代码中我能够读出这个注释并将所需的IsCrossRef添加到生成的schema.xml中吗?

1 个答案:

答案 0 :(得分:2)

在阅读了一些源代码后,我自己找到了答案:

如果你想完成这个,你需要修改文件:MysqlSchemaParser.php,位于:propel1 / generator / lib / reverse / mysql(与作曲家一起安装时)

将第99行的记录集更改为:

while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    $name = $row[0];
    $type = $row[1];

    if ($name == $this->getMigrationTable() || $type != "BASE TABLE") {
        continue;
    }
    /*
        Edit : Find out if table isCrossRef 
    */
    $commentStmt = $this->dbh->query("show table status like '".$name."'");
    $commentRow  = $commentStmt->fetch(PDO::FETCH_OBJ);
    $isCrossRef = (strtolower($commentRow->Comment) == 'iscrossref');
    /*
        End of edit
    */

    if ($task) {
        $task->log("  Adding table '" . $name . "'", Project::MSG_VERBOSE);
    }

    $table = new Table($name);
    $table->setIdMethod($database->getDefaultIdMethod());
    $table->setIsCrossRef($isCrossRef); /*EDIT : set is crossref to true*/
    $database->addTable($table);
    $tables[] = $table;
}