Php 原则2类表继承YML
我试图在ZF2和Doctrine 2中使用类表继承。我的实现非常简单。我想我已经把类结构都设置好了,但是我想在某些地方可能有设置上的问题。不幸的是,我找到了很多关于类设置的文档,但没有找到关于YML实现的全部文档。每个人似乎都求助于使用条令工具来生成一切。关于如何设置,使用条令工具有点问题,尤其是在使用ZF2时。此外,我认为这是一个学习的机会。因此,以下是我所拥有的: 当前问题:我没有从子类/表中获取任何数据:Php 原则2类表继承YML,php,doctrine-orm,zend-framework2,class-table-inheritance,Php,Doctrine Orm,Zend Framework2,Class Table Inheritance,我试图在ZF2和Doctrine 2中使用类表继承。我的实现非常简单。我想我已经把类结构都设置好了,但是我想在某些地方可能有设置上的问题。不幸的是,我找到了很多关于类设置的文档,但没有找到关于YML实现的全部文档。每个人似乎都求助于使用条令工具来生成一切。关于如何设置,使用条令工具有点问题,尤其是在使用ZF2时。此外,我认为这是一个学习的机会。因此,以下是我所拥有的: 当前问题:我没有从子类/表中获取任何数据: .array(1) { [0] => class MyCompany\Doma
.array(1) {
[0] =>
class MyCompany\Domain\Model\Customer\CustomerNote#2852 (9) {
protected $customer =>
NULL
protected $note =>
string(13) "Clever Note 1"
protected $id =>
string(1) "1"
protected $disabled =>
NULL
protected $modified =>
class DateTime#2884 (3) {
...
通用注释类/表:
CREATE TABLE generic_notes
(
note_id serial NOT NULL,
discriminator character varying(255) NOT NULL,
note text,
created timestamp with time zone NOT NULL DEFAULT now(),
created_by_id bigint NOT NULL,
modified timestamp with time zone,
modified_by_id bigint,
disabled timestamp with time zone NOT NULL DEFAULT 'infinity'::timestamp with time zone,
CONSTRAINT generic_notes_pkey PRIMARY KEY (note_id),
CONSTRAINT generic_notes_created_by_id_fkey FOREIGN KEY (created_by_id)
REFERENCES users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE RESTRICT,
CONSTRAINT generic_notes_modified_by_id_fkey FOREIGN KEY (modified_by_id)
REFERENCES users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE RESTRICT
)
客户注释类/表(继承通用注释):
YML映射用于注释:
MyCompany\Domain\Model\Note:
type: entity
table: generic_notes
inheritanceType: JOINED
discriminatorColumn:
name: discriminator
type: string
length: 255
discriminatorMap:
customer: MyCompany\Domain\Model\Customer\CustomerNote
id:
id:
column: note_id
type: bigint
generator:
strategy: IDENTITY
fields:
note:
type: text
nullable: true
created:
type: datetimetz
modified:
type: datetimetz
nullable: true
disabled:
type: datetimetz
nullable: true
manyToOne:
createdBy:
targetEntity: MyCompany\Domain\Model\User
joinColumn:
name: created_by_id
referencedColumnName: user_id
modifiedBy:
targetEntity: MyCompany\Domain\Model\User
joinColumn:
name: modified_by_id
referencedColumnName: user_id
客户注释映射:
MyCompany\Domain\Model\Customer\CustomerNote:
type: entity
table: customer_notes
manyToOne:
customer:
targetEntity: MyCompany\Domain\Model\Customer
inversedBy: customerNote
joinColumn:
name: customer_id
referencedColumnName: customer_id
通用注释实体
<?php
namespace MyCompany\Domain\Model;
use MyCompany\Domain\Model\Entity\AbstractEntity;
use MyCompany\Domain\Model\Entity\DisabledTrait;
use MyCompany\Domain\Model\Entity\TimestampedInterface;
use MyCompany\Domain\Model\Entity\TimestampedTrait;
/**
* Class Note
*
* @package MyCompany\Domain\Model
*/
class Note extends AbstractEntity implements TimestampedInterface
{
use DisabledTrait;
use TimestampedTrait;
/**
* @var string
*/
protected $note;
/**
* @param string $note
* @return $this
*/
public function setNote($note)
{
$this->note = $note;
return $this;
}
/**
* @return string
*/
public function getNote()
{
return $this->note;
}
}
客户注释夹具数据:
generic_notes:
-
note_id: 1
discriminator: customer
note: Clever Note 1
created: "2012-01-23 05:43:21.000000"
created_by_id: 1
modified: "2012-01-24 05:43:21.000000"
modified_by_id: 2
disabled: null
customer_notes:
-
note_id: 1
customer_id: 1
以上一切都是完全有效和有效的。似乎我没有为客户notes单元测试包含notes夹具数据,反之亦然。所以,为了我自己的愚蠢,我在洞里呆了好几天
generic_notes:
-
note_id: 1
discriminator: customer
note: Clever Note 1
created: "2012-01-23 05:43:21.000000"
created_by_id: 1
modified: "2012-01-24 05:43:21.000000"
modified_by_id: 2
disabled: null
customer_notes:
-
note_id: 1
customer_id: 1