Coldfusion ORM获得外部密钥

时间:2013-07-24 23:29:25

标签: orm coldfusion

我有一个Coldfusion orm应用程序有两个对象:

Widget.cfc

// Primary Key
property name="id" fieldtype="id" column="" generator="native";

// Properties
property name="col" type="string";
property name="created_at" type="date";
property name="kind" type="string";
property name="name" type="string";
property name="label" type="string";
property name="range" type="string";
property name="row" type="numeric";
property name="size" type="numeric";
property name="size_x" type="numeric";
property name="size_y" type="numeric";
property name="source" type="string" default="null";
property name="targets" type="numeric";
property name="update_interval" ormtype="int";
property name="update_at" type="date";

//Relationship
property name="dashboards" fieldtype="many-to-many" 
        linktable="DashboardWidgets" 
        type="array" cfc="dashboard" 
        cascade="all-delete-orphan" inverse="true" singularname="dashboard";

和dashboard.cfc

// Primary Key
property name="id" fieldtype="id" column="id" generator="native";

// Properties
property name="name" type="string";
property name="time" type="timestamp";
property name="layout" type="string";
property name="created_at" type="timestamp";
property name="updated_at" type="timestamp";
property name="locked" type="boolean";

//Relationships 
property name="widgets" fieldtype="many-to-many" 
    linktable="DashboardWidgets" type="array" cfc="widget" 
    cascade="all-delete-orphan" singularname="widget";

我需要输出widget.cfc的所有属性的json以及关系中定义的仪表板ID。

所以我拥有的是:

[{"id":5,"kind":"number",
"name":"dsfasdfa",
"size_x":1,
"size_y":1,
"source":"demo",
"update_interval":36000,
"dashboards":[{"id":3,"name":"Undefined name",
    "time":"July, 24 2013 20:52:44 +0200",
    "layout":"test",
    "created_at":"July, 24 2013 20:52:44 +0200",
    "updated_at":"July, 24 2013 20:52:44 +0200",
    "locked":false,
    "widgets":null}]
}]

我需要的东西是:

[{"id":5,
"kind":"number",
"name":"dsfasdfa",
"size_x":1,
"size_y":1,
"source":"demo",
"update_interval":36000,
"dashboard_id":3
}]

我怎样才能做到这一点?我只需要仪表板的id。

1 个答案:

答案 0 :(得分:0)

我找到了获得此in the documentation的方法:

<cfproperty name="art" 
      fieldtype="one-to-many" 
      cfc="ART" 
      fkcolumn="artistId" 
      lazy="true">