Login

    Register

Managed Hosting

PROJECT CATEGORIES

 

DataMgr
Project Home Blog Forums Known Issues External Project Link Contact Project

DataMgr Issue: Bug Saving List Relations with Mismatched Foreign Keys

Name: Bug Saving List Relations with Mismatched Foreign Keys
ID: 5
Project: DataMgr
Type: Bug
Area: Code
Severity: Normal
Status: Fixed
Related URL:
Creator: Ron Hopper
Created: 08/02/13 8:31 AM
Updated: 09/16/13 1:23 PM
Description: When setting up a schema like so:
--------------------------------------------------------------------------------
<table name="users">
<field ColumnName="id" CF_DataType="CF_SQL_BIGINT" PrimaryKey="true" Increment="true" AllowNulls="false" />
<field ColumnName="group_ids">
<relation type="list" table="groups" join-table="group_membership" field="id"
local-table-join-field="id" join-table-field-local="user_id"
remote-table-join-field="id" join-table-field-remote="group_id"
sort-field="id" distinct="true" />
</field>
</table>

<table name="groups">
<field ColumnName="id" CF_DataType="CF_SQL_BIGINT" PrimaryKey="true" Increment="true" AllowNulls="false" />
<field ColumnName="name" CF_DataType="CF_SQL_VARCHAR" Length="20" />
</table>

<table name="group_membership">
<field ColumnName="id" CF_DataType="CF_SQL_BIGINT" PrimaryKey="true" Increment="true" AllowNulls="false" />
<field ColumnName="user_id" CF_DataType="CF_SQL_BIGINT" AllowNulls="false" />
<field ColumnName="group_id" CF_DataType="CF_SQL_BIGINT" AllowNulls="false" />
</table>
--------------------------------------------------------------------------------

I am getting an error on insertRecord which fails when trying to save the "group_ids" relation. I am using DataMgr 2.5 and I found the problem in _DataMgr.cfc in the "saveRelations" function around line 5298. The code was:

--------------------------------------------------------------------------------
<cfif Len(relates[i].Relation["join-table-field-local"])>
<cfset fieldPK = relates[i].Relation["join-table-field-local"]>
<cfif relates[i].Relation["join-table-field-local"] NEQ getPrimaryKeyFieldName(arguments.tablename)>
<cfset temp = StructNew()>
<cfset temp[getPrimaryKeyFieldName(arguments.tablename)] = arguments.pkval>
<cfset qRecord = getRecords(tablename=arguments.tablename,data=temp,fieldlist=fieldPK)>
<cfset arguments.pkval = qRecord[fieldPK][1]>
</cfif>
<cfelse>
<cfset fieldPK = getPrimaryKeyFieldName(arguments.tablename)>
</cfif>               
--------------------------------------------------------------------------------

and I changed the relation field name in the 3rd line. The new code is:

--------------------------------------------------------------------------------
<cfif Len(relates[i].Relation["join-table-field-local"])>
<cfset fieldPK = relates[i].Relation["join-table-field-local"]>
<cfif relates[i].Relation["local-table-join-field"] NEQ getPrimaryKeyFieldName(arguments.tablename)>
<cfset temp = StructNew()>
<cfset temp[getPrimaryKeyFieldName(arguments.tablename)] = arguments.pkval>
<cfset qRecord = getRecords(tablename=arguments.tablename,data=temp,fieldlist=fieldPK)>
<cfset arguments.pkval = qRecord[fieldPK][1]>
</cfif>
<cfelse>
<cfset fieldPK = getPrimaryKeyFieldName(arguments.tablename)>
</cfif>               
--------------------------------------------------------------------------------

Please verify this bug and include this patch in the next release.
Thanks,
- Ron Hopper
History: Created by adelphus (Ron Hopper) : 08/02/13 8:31 AM

Comment by sebtools (Steve Bryant) : 09/16/13 1:23 PM
Ron,

This should be taken care of now.

Thanks for the catch!

Steve

Updated by sebtools (Steve Bryant) : 09/16/13 1:23 PM
This should be fixed now.

Thanks for the catch!

Steve

To add a comment to this bug, please login using the link above.