教义行为,如果我这样做,会是正确的吗?

发布于 2024-10-19 18:38:39 字数 563 浏览 9 评论 0 原文


我正在 ZF + Doctrine 1.2.3 中做一个 Web 应用程序,但我有一个旧数据库,

它有很好的结构,所以我想我可以用 Doctrine Commad 对其进行逆向工程

./doctrinegenerate-models-db

这很神奇,但是当我想使用一些学说行为(例如:searchable)作为示例时,我停了下来。

我的问题:如果我转到我的模型并添加这两行:

$this->actAs('Searchable', array(
  'fields' => array('title', 'content')
   )
);

我不确定这是否足够并且会按预期工作。如果您对手动创建其他行为(如 versionablei18nsluggablesoft delete)有更多提示或者用教条行为对其进行逆向工程,你能列出它们吗?

I am doing a web application in ZF + Doctrine 1.2.3 but i had an old database ,

it had pretty good structure so i think i can reverse engineer it with doctrine commad

./doctrine generate-models-db ,

It's amazing but I stopped when I wanted to use some doctrine behaviors like : searchable as an example.

My question: if I went to my model and added these two lines :

$this->actAs('Searchable', array(
  'fields' => array('title', 'content')
   )
);

I am not sure if that is enough and would work as expected. If you had any more tips about creating other behaviors (like versionable, i18n, sluggable or soft delete ) manually or reverse engineer it with doctrine behaviors, could you please list them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-10-26 18:38:39

您是否希望对数据库进行逆向工程,然后使用可搜索等行为?

首先,您可以使用“generate-yaml-db”CLI 任务从现有数据库模式生成 YAML 文件。此后,您可以设置关系并添加必要的行为,例如时间戳、可搜索,或者您可以推出自己的行为。完成所有这些后,您可以使用“generate-models-yaml”CLI 任务生成模型。

如果您添加了行为或对架构进行了任何更改,您可以生成迁移差异“generate-migrations-diff”。这将创建迁移类,可用于将 YAML 文件中所做的新更改应用到数据库。运行“迁移”CLI 任务以将更改应用到数据库。

希望有帮助。

Are you looking to reverse engineer your database and then use behaviors such as Searchable?

To start with you can generate a YAML file from the existing db schema using the "generate-yaml-db" CLI task. Thereafter you can set-up the relationships and add the necessary behaviors such as Timestampable, Searchable or you can roll out your own. Once all this is done you can generate the models using "generate-models-yaml" CLI task.

If you have added behaviors or made any changes to the schema you could generate a migration diff "generate-migrations-diff". This create the migration classes which can be used to apply the new changes made in the YAML file to the db. Run the "migrate" CLI task to apply the changes to the db.

Hope it helps.

人海汹涌 2024-10-26 18:38:39

仅仅添加

$this->actAs('Searchable', array(
'fields' => array('title', 'content')
 )
);

是不够的。我自己从未使用过它,但是如果您查看 docs,您会看到它为索引生成了另一个表。

CREATE TABLE job_index (id BIGINT, 
keyword VARCHAR(200), 
field VARCHAR(50), 
position BIGINT, 
PRIMARY KEY(id, keyword, field, position)) ENGINE = INNODB

对于像这样的模型定义,

class Job extends Doctrine_Record
{
    public function setUp()
    {
        $this->actAs('Searchable', array(
                'fields' => array('title', 'content')
            )
        );
    }
 //....more methods
}

如果您需要比 Doctrine 可以做的更多的搜索行为,您应该使用 全文搜索 甚至像 Lucene 这样的外部解决方案(带有可选的 Solr)symfony 中的 Doctrine Searchable Behavior 与 Zend Lucene 可能会为您提供更多相关信息。如果您有大量数据需要搜索并且需要精细控制,那么您应该非常仔细地研究 Lucene,因为在大多数情况下它会击败纯粹的 MySQL/Doctrine 解决方案。

Simply adding

$this->actAs('Searchable', array(
'fields' => array('title', 'content')
 )
);

is not enough. I never used it myself but if you look at the docs, you see that it generates another table for the index.

CREATE TABLE job_index (id BIGINT, 
keyword VARCHAR(200), 
field VARCHAR(50), 
position BIGINT, 
PRIMARY KEY(id, keyword, field, position)) ENGINE = INNODB

for a model definition like

class Job extends Doctrine_Record
{
    public function setUp()
    {
        $this->actAs('Searchable', array(
                'fields' => array('title', 'content')
            )
        );
    }
 //....more methods
}

If you need heave search behavious that do more than what Doctrine can do, you should look at search on a databaes level with fulltext-searches or even external solution like Lucene (with optional Solr) Doctrine Searchable Behavior vs Zend Lucene in symfony may give you more information about that. If you have lots of data to search and need fine controll, you should look into Lucene very carefully since it will beat a pure MySQL/Doctrine solution in most cases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文