有3个表:shelf、section和shelf_has_section中间表来支持nm关系。从 symfony 学说构建的模式:build-schema 如下所示。
简单地,
shelf(id, position)
section(id, name)
shelf_has_section(shelf_id, section_id, number_of_books)
架构。
Shelf:
connection: doctrine
tableName: shelf
columns:
id:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
position:
type: string(255)
primary: false
notnull: true
autoincrement: false
relations:
ShelfHasSection:
local: id
foreign: shelf_id
type: many
Section:
connection: doctrine
tableName: section
columns:
id:
type: integer(1)
primary: true
autoincrement: false
name:
type: string(20)
primary: false
notnull: true
relations:
ShelfHasSection:
local: id
foreign: section_id
type: many
ShelfHasSection:
connection: doctrine
tableName: shelf_has_section
columns:
shelf_id:
type: integer(4)
primary: true
autoincrement: false
section_id:
type: integer(1)
primary: true
autoincrement: false
number_of_books:
type: integer(4)
primary: false
notnull: false
autoincrement: false
relations:
Shelf:
local: shelf_id
foreign: id
type: one
Section:
local: section_id
foreign: id
type: one
通过在架构中添加以下与 Shelf 的关系,我设法将 Sections 显示为复选框列表。我还需要在部分复选框前面显示一个文本字段以输入书籍数量。
Sections:
class: Section
refClass: ShelfHasSection
local: shelf_id
就像检查可用部分的复选框列表并添加已检查部分的书籍数量一样。
我试图通过 embedRelation() 等实现它,但缺乏我的 symfony 知识并没有让我到达那里。任何帮助高度赞赏。