gamma / fixtures-generator
此包最新版本(dev-master)没有可用的许可证信息。
Symfony2 fixtures 生成器
dev-master
2018-11-22 07:13 UTC
Requires
- php: >=5.3
- symfony/framework-bundle: ~2.3|~3.0
This package is not auto-updated.
Last update: 2024-09-28 20:25:18 UTC
README
通过从项目的数据库生成 fixtures 类来加速 fixtures 的创建
安装
composer require --dev gamma/fixtures-generator
将以下代码添加到 AppKernel.php 的开发部分
$bundles[] = new Gamma\FixturesGeneratorBundle\GammaFixturesGeneratorBundle();
## 配置
添加到 app/config.yml
gamma_fixtures_generator
fixture_references_file_name: /var/fixtureReferences.txt
Fixtures 生成器使用说明
app/console gamma:fixtures:generate "\Gamma\Bundle\Entity\Item" - generate all entities from table
app/console gamma:fixtures:generate "\Gamma\Bundle\Entity\Item" --id="1,2,3" - generate entities with ids 1,2,3 from table
app/console gamma:fixtures:generate "\Gamma\Bundle\Entity\Item" --id="1,2,3" --force-add-reference - generate entities with ids 1,2,3 from table and add txt reference
注意
1. 尽管在 fixtures 加载前使用 schema recreate 重置了自增生成器,但最好还是通过直接设置器使用定义的 ID
为每个 fixtures 类添加以下内容
$metadata = $manager->getClassMetaData('\Gamma\Bundle\Entity\Item');
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
- 多对多关系应该额外手动创建