Scaffoldnig and CF9 orm : many-to-many relations broken?

16 views
Skip to first unread message

marc

unread,
Jan 31, 2012, 6:49:05 AM1/31/12
to model...@googlegroups.com
Hi,

I use MG scaffolding with CF9 orm to add records to a 3-table db.

Tables: category,message,comment.
Relations:
Category->message is many-to-many;
message->comment is one-to-many;
comment->message is many-to-one.

I have set up scaffolding by including in the ModelGlue.xml this:
    <scaffold object="category" event-type="mainLayout" />
    <scaffold object="comment" event-type="mainLayout" />
    <scaffold object="message" event-type="mainLayout" />
I have configured 3 cfc's to be persistent, with their properties reflecting columns and relationships.

This is all that is needed for adding, deleting, viewing etc the table records.

I can add categories,messages and comments using the MG generated templates. Comments I add get associated with their assigned messages. Also categories get added and messages get added. When adding a message I have to indicate the associated category by checking a checkbox for te categoryname in the message form. But after submitting that messages, it gets added but it never get assigned with the category.
The linktable stays empty,

When poking in the framework I saw in
/ModelGlue/gesture/modules/orm/cform/cfORMAdapter.cfc assemble()
where the submitted form is being parsed to create relationships that for the many-to-many relation to exist an eventkey has to be persent that doesn't exist:

assemble()
[...]
var eventKey = property.alias & "|" & property.sourceKey;
                    if (arguments.event.valueExists(eventKey)) {
[...]

translates in the case of submitting a messageform to

"categoryArray|categoryId"

so I need an event key "categoryArray|categoryId" with the id value of the associated category.
In the form I have those 3 categories (the checkboxes) which named

Category Array|categoryId.

Since "categoryArray|categoryId" neq "Category Array|categoryId" I assume this is the reason a many-to-many relationship is never working in this case.

Am I off track here? Is this a bug and should it be filed?

Marc

marc

unread,
Jan 31, 2012, 6:57:19 AM1/31/12
to model...@googlegroups.com
Here is the setup for the persistent cfc's:

categories.cfc

<cfcomponent
    displayname="category"
    persistent="true"
    output="false"
    table="category"
    entityname="category"
    beans="commentGateWay">

    <cfproperty name="categoryId" column="id" fieldType="id" generated="always" generator="increment" displayname="id" ormType="integer" setter="false"/>
    <cfproperty name="description" column="description" default="" displayname="description" fieldType="column" type="string" />
    <cfproperty name="name" column="name" default="" displayname="name" fieldType="column" type="string" />
    <!--- relations --->
    <cfproperty
        name="message"
        fieldType="many-to-many"
        cfc="message"
        linktable="categoryMessage"
        fkcolumn="FK_category"
        inversejoincolumn="FK_message"
        type="array"/>


message.cfc:

<cfcomponent
    displayname="message"
    persistent="true"
    output="false"
    table="message"
    entityname="message">

    <cfproperty name="messageId" setter="false" column="id" fieldtype="id" generator="increment" generated="always" type="numeric" />
    <cfproperty name="content" default="" displayname="content" type="string" />
    <cfproperty name="date" default="" displayname="date" type="date" />
    <cfproperty name="subject" default="" displayname="subject" type="string" />
    <!--- relations --->
    <cfproperty
        name="categoryArray"
        fieldType="many-to-many"
        linktable="categoryMessage"
        cfc="category"
        fkcolumn="FK_message"
        inversejoincolumn="FK_category"
        inverse="true"
        type="array"/>
    <cfproperty
        name="comments"
        fieldType="one-to-many"
        cfc="comment"
        fkcolumn="commentId"
        type="Array"
        lazy="true" />


comment.cfc:

<cfcomponent
    displayname="comment"
    persistent="true"
    output="false"
    table="comment"
    entityname="comment">

    <cfproperty name="commentId" column="id" fieldtype="id" generated="always" generator="increment" ormtype="integer" setter="false"/>
    <cfproperty name="subject" default="" displayname="subject" type="string" />
    <cfproperty name="content" default="" displayname="content" type="string" />
    <!--- relations --->
    <cfproperty name="message" fieldType="many-to-one" cfc="message" fkcolumn="messageId" >

Reply all
Reply to author
Forward
0 new messages