首先,表结构的相关位:这种关系在CF9的ORM中可能吗?怎么样?
contact
-contactID
-email
data
-value
-contactID
-definitionID
definition
-definitionID
-name
在contact
表中的每个记录代表一个有自己的E-mail地址沿着单一的接触。
definition
表中的每条记录表示自定义数据字段的定义。例如,definition
中可能有五条记录 - 组织,邮编,评论,地址,电话。除了这些字段的名称之外,它还定义了有关这些字段的相关元数据。
data
表中的每条记录都包含与联系人相关的自定义数据字段的值。其定义取自definition
表。
为了进一步澄清,如果我想与他们的自定义字段数据一起产生接触的表,它可能是这样的:
| E-Mail | Organization | Zip Code | Comments | Address | Phone |
-------------------------------------------------------------------------------------------------------------
| [email protected] | ACME | 12345 | Cool guy! | 123 Test St | 555-5555 |
| [email protected] | SomeCo. | 54321 | Doesn't know anything about ORM! | 321 Test Blvd | 444-4444 |
该系统的好处是,它可以扩展为多因为我需要它并且很容易定制。不利的是,我不知道如何界定的关系:)
我已经尝试定义contact:data
为1:M
和definition:data
为1:M
,但结果看起来有点奇怪:有两个触点和单一的定义,添加对每个联系人排列数据,然后调用entityLoad('Contact')
产生一个有趣的关系。它看起来像这样(只是要使用一些伪结构符号,因为它很容易输入,而且我希望,读):
{
contact: {
email: '[email protected]',
data: {
value: 'ACME',
definition: {
name: 'Organization',
data: {
value: 'SomeCo.',
contact: {
email: '[email protected]'
}
}
}
}
}
它看起来就像是创造contact
和definition
之间的间接关系,根据data
表与两个表的关系。正如你所想象的,增加联系人和自定义字段的数量只会使问题呈指数级恶化。
这种类型的关系可能使用CF9的ORM吗?我怎样才能做到这一点?
在此先感谢!
编辑:忘了指定 - 我使用MySQL,如果它很重要。
编辑2:CFC定义遵循:
Contact.cfc
/**
* @persistent true
*/
component name='Contact' {
/**
* @type numeric
* @sqltype int(11)
* @generator increment
* @fieldtype id
*/
property contactID;
/**
* @type string
* @sqltype varchar(50)
*/
property email;
/**
* @type array
* @fieldtype one-to-many
* @cfc Data
* @fkcolumn dataID
*/
property data;
}
Definition.cfc
/**
* @persistent true
*/
component name='Definition' {
/**
* @type numeric
* @sqltype int(11)
* @generator increment
* @fieldtype id
*/
property definitionID;
/**
* @type string
* @sqltype varchar(50)
*/
property name;
/**
* @type array
* @fieldtype one-to-many
* @cfc Data
* @fkcolumn dataID
*/
property data;
}
Data.cfc
/**
* @persistent true
*/
component {
/**
* @type numeric
* @sqltype int(11)
* @generator increment
* @fieldtype id
*/
property dataID;
/**
* @type string
* @sqltype varchar(50)
*/
property value;
/**
* @fieldtype many-to-one
* @fkcolumn contactID
* @cfc Contact
* @inverse true
*/
property contact;
/**
* @fieldtype many-to-one
* @fkcolumn definitionID
* @cfc Definition
* @inverse true
*/
property definition;
}
我相信你想要实现的数据属性一个多到多的接触和定义与数据作为你的“LinkTable”之间的关系:HTTP: //help.adobe.com/zh_CN/ColdFusion/9.0/Developing/WS5FFD2854-7F18-43ea-B383-161E007CE0D1.html – 2012-01-31 22:11:40
第二个想法,我不知道你将如何访问“数据”中的“值”字段,如果你用它作为多对多的链接表。也许正确的做法是定义联系人和数据之间的一对多关系,然后在数据和定义之间建立多对一的关系。 – 2012-01-31 22:19:05
@ Danimal37感谢您的意见!正如我的问题所指出的那样,我将'definition:data'和'contact:data'定义为一对多,并且得到了上面的结果:) – 2012-01-31 22:44:32