模式生成器:强制字段基数生成错误的 ORM 基数
The Schema Generator: forcing a field cardinality generates a wrong ORM cardinality
当我尝试强制基数时,模式生成器在 PHP 文件中生成错误的 ORM 基数,简短示例:
YAML 配置文件:
CreativeWork:
properties:
comment: { range: "Comment", cardinality: "(1..*)" }
Comment:
properties: {}
已生成 PHP 文件:
/**
* @var Collection<Comment>|null comments, typically from users
*
* @ORM\ManyToMany(targetEntity="App\Entity\Comment")
* @ORM\JoinTable(inverseJoinColumns={@ORM\JoinColumn(nullable=false, unique=true)})
* @ApiProperty(iri="http://schema.org/comment")
*/
private $comments;
预期关系:OneToMany;实际:多对多。
我是不是漏掉了什么?
干杯
从 library source 可以看出,生成 OneToMany 注释 mappedBy
参数是必需的。可能是文档不完整。
不过,您可以随意更改任何生成的代码。比如你需要单向关联。
当我尝试强制基数时,模式生成器在 PHP 文件中生成错误的 ORM 基数,简短示例:
YAML 配置文件:
CreativeWork:
properties:
comment: { range: "Comment", cardinality: "(1..*)" }
Comment:
properties: {}
已生成 PHP 文件:
/**
* @var Collection<Comment>|null comments, typically from users
*
* @ORM\ManyToMany(targetEntity="App\Entity\Comment")
* @ORM\JoinTable(inverseJoinColumns={@ORM\JoinColumn(nullable=false, unique=true)})
* @ApiProperty(iri="http://schema.org/comment")
*/
private $comments;
预期关系:OneToMany;实际:多对多。
我是不是漏掉了什么?
干杯
从 library source 可以看出,生成 OneToMany 注释 mappedBy
参数是必需的。可能是文档不完整。
不过,您可以随意更改任何生成的代码。比如你需要单向关联。