我在尝试实施 CTI 时遇到很多问题
首先,我为我的实体类使用自定义加载器
class My_AutoLoader implements Zend_Loader_Autoloader_Interface
{
public function autoload($class)
{
$class = trim(str_replace('\\', '/', $class), '/');
if (@include(APPLICATION_PATH . '/Entities/' . $class . '.php')) {
return $class;
} else {
throw new Zend_Loader_Exception('Cannot load ' . $class . '.');
}
}
}
这个想法是application\Entities
用于没有命名空间的类$user = new Users();
然后我定义了类继承
Profiles:
type: entity
table: profiles
repositoryClass: Repositories\Base
inheritanceType: JOINED
discriminatorColumn:
name: profiletype
type: integer
length: 11
discriminatorMap:
1: Personal
2: Work
3: Business
id:
id:
type: integer
generator:
strategy: AUTO
fields:
firstname:
type: string
length: 255
fixed: false
nullable: true
...
Work:
type: entity
table: work
repositoryClass: Repositories\Base
fields:
position:
type: string
length: 255
fixed: false
nullable: true
然后我手动创建了类 Work 来扩展 Profiles
class Work extends Profiles
{
}
第一个问题从 2.0.0 (2.0.1) 开始,当我使用控制台工具的generate-entities时,我得到一个错误,即我没有Work
类Work
的 id,这很奇怪,因为恕我直言,它与扩展Profiles
和扩展的想法相矛盾id
已经定义了。
但是,我尝试id
为Work
该类添加一列,但随后我收到一条消息,指出我已经有一个列id
。哦!
我尝试为 PK 添加一些其他列名,但实际上我得到了一个不必要的额外列,id
因为还创建了正确的继承列。在 CTI 中,我应该有一个 FK 列,并且没有其他 PK 具有自动生成的值。
所以我做了坏事来破解教义类并删除对丢失ID的检查。丑陋但有效。实体开始正确生成,数据库结构很好。
后来我发现所有这些奇怪的行为都是由于教义 2 中的一个错误,它在 2.0.5 中得到了修复。
好吧,我尝试了 2.0.5 并且遇到了完全相同的问题,所以我认为错误出在我的代码中。
我在学说的 jira 中提交了一个错误,我得到的回答是我的定义是错误的,我需要子类的 id(并且参考了我们所知道的文档很差,尤其是对于 YAML 映射)。我放弃并坚持我的黑客。
后来我尝试使用 2.0.6 和 2.1,但是对于这些版本,我的实体不再更新,但是每次我使用 generate-entities 时,新的类定义都被附加到末尾,所以会有重复。
我的问题是:
这是教义的问题还是我做错了?
如果在我身上,映射 CI 的正确方法是什么