【发布时间】:2011-10-28 19:46:56
【问题描述】:
cross-reference tables 的理念是在 Propel 1.5 中引入的。这意味着实体可以获得相关项目的列表,就好像它是一对多关系一样。所以在人到组的关系中,一个人可以调用getGroups(),一个组可以调用getPersons()。
这使事情更容易处理。但是,如果实体与自身具有多对多关系,则函数调用的名称会变得更加复杂。例如,以下允许组在其内部包含组:
group:
id: ~
name: { type: varchar(255) }
sub_group:
group_id:
type: integer
primaryKey: true
foreignTable: group
foreignReference: id
required: true
sub_group_id:
type: integer
primaryKey: true
foreignTable: group
foreignReference: id
required: true
对于这种关系,Propel 生成了名称尴尬的函数getGroupsRelatedByGroupId() 和getGroupsRelatedBySubGroupId()。这些很长,而且不是很明显。作为这个实体的用户,我更喜欢使用getParentGroups()和getSubGroups()这两个函数,我理解的更清楚。是否可以告诉 Propel 重命名这些函数? phpName 属性似乎没有这样做。
一对多关系也会出现问题,如下面非常简化的示例所示:
child:
id: ~
father_id:
type: integer
foreignTable: person
mother_id:
type: integer
foreignTable: person
在上面,一个子对象将被赋予函数getPersonRelatedByFatherId() 和getPersonRelatedByMotherId(),而getMother() 和getFather() 应该会更好地工作。可以编写自定义函数来执行此操作,但能够在架构中定义它会更有意义。
【问题讨论】:
标签: symfony1 many-to-many symfony-1.4 yaml propel