Did you try Aliasing the column names using the <field> tag?


< object name = "TableA" >

<field name="duplicate" alias="duplicate1" />

< hasOne name = "TableB" >

            < relate from =" TableBId" to = "TableBId" />

      </ hasOne >

</ object >

< object name = "TableB" >

      <field name="duplicate" alias="duplicate2" />

        < hasMany name = "TableA" >

            < relate from = "TableBId" to = "TableBId" />

      </ hasMany >

</ object >

This tag is in the reactor docs
Hope this helps,
Doug S.
www.Evenamonkey.com


On 7/13/06, Porter, Benjamin L. < [EMAIL PROTECTED]> wrote:

I did not see if this has been corrected or not. I'm running about a month old version of reactor.  Is this bug in the trac?

There is a bug in returnObjectField when 2 tables in a join are named the same.

 

I have 2 tables that are joined like so

 

< object name = "TableA" >

< hasOne name = "TableB" >

            < relate from =" TableBId" to = "TableBId" />

      </ hasOne >

</ object >

 

< object name = "TableB" >

      < hasMany name = "TableA" >

            < relate from = "TableBId" to = "TableBId" />

      </ hasMany >

</ object >

 

Table A and Table B both contain a column named [DuplicateColumnName] that is not a foreign or primary key.

 

If you write an object query to get just the [DuplicateColumnName] from table B It will create a select statement to return both [TableA].[DuplicateColumnName] and [TableB].[DuplicateColumnName]  which coldfusion can not decide which column to throw in a query object and you have a 50 / 50 chance of getting the wrong data back.

 

The oo query should only be returning [TableB].[DuplicateColumnName]

 

Coldfusion code oo query

var qry = CreateQuery();

                                                // join on the TableB table

              qry.innerJoin("TableA", "TableB", "TableB");

                                    // limit results

            qry.getWhere().isEqual("TableA","TableAID",Arguments.ID);

            qry.getWhere().isEqual("TableB","IsActive",1);

                                                // get only the relevant fields

            qry.returnObjectField("TableA", "AColumn");

            qry.returnObjectField("TableA", "AnotherColumn");

            qry.returnObjectField("TableB","Description");

                                    // order by

            qry.getOrder().setAsc("TableA","FirstName");

 

 

SQL actually sent

 

SELECT           

[TableA].[AnotherColumn] AS [AColumn],

[TableA].[AnotherColumn] AS [AnotherColumn],

 [TableA].[DuplicateColumnName] AS [DuplicateColumnName],

                        [TableB].[DuplicateColumnName] AS [DuplicateColumnName]

 

FROM              

[TableA] AS [TableA]

                        INNER JOIN [TableB] AS [TableB] ON [TableB].[TableBID] = [TableA].[TableAID]

 

WHERE           

[TableA].[TableAID] = 21212

AND                 [TableB].[IsActive] = 1

 

ORDER BY      

[TableA].[FirstName]

 

 



-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to