1 Reply Latest reply on May 17, 2010 7:54 PM by rewheaton

    CF9 ORM Relational Mapping + Flash Builder 4 nested value objects errors

    sir_teddy

      Hi all,

       

      I have been trying to use ORM relational mapping in ColdFusion 9 and combine that with Flash Builder Beta 2 to manipulate data. What i have are a two simple tables containing 3 columns each:

       

      Properties table:

      ID ( primary key )

      PropertyName (data)

      Tenants ( unique id )

       

      Tenants table:

      ID ( primary key )

      TenantName ( data )

      TenantID ( unique id )

       

      And two cfc for each table.

       

      Tenants cfc:

      <cfcomponent persistent="true" table="Tenants"  schema="dbo" output="false">
           <!---- properties ---->
           
           <cfproperty name="ID" column="ID" type="numeric" ormtype="int" fieldtype="id"  /> 
           <cfproperty name="TenantName" column="TenantName" type="string" ormtype="string"  />
              <cfproperty name="TenantID" column="TenantID" type="numeric" ormtype="int" />
           
      </cfcomponent> 
      
       
      

       

      Property cfc:

      <cfcomponent persistent="true" table="Properties"  schema="dbo" output="false">
           <!---- properties ---->
           
           <cfproperty name="ID" column="ID" type="numeric" ormtype="int" fieldtype="id"  /> 
           <cfproperty name="PropertyName" column="PropertyName" type="string" ormtype="string"  />
           
           <!---- relation ---->
           <cfproperty name="Tenants"
                          fieldtype="one-to-many"
                          singularname="Tenant"
                          cfc="Tenants"
                          mappedby="Tenants"
                          fkcolumn="TenantID" 
                          lazy="false" 
                          type="array"
                                      <!--- can be array or struct --->  
                          <!---structkeytype="int" structkeycolumn="ID"--->
                          />
           
      </cfcomponent> 
      

       

      And the i test to see how the data comes back with this:

       

      test.cfml

      <cfset ormReload()>
      <cfset properties = entityLoad('Properties')>
      <cfdump var = "#properties#" />
      

       

      The output is as it is suppose to be; i get an array of Properties objects populated with all data and the Tenants property populated with an array of Tenants objects. The problem occurs when i try to load the data using flash builder through a service using RemoteObject.

       

      Flex app:

      protected function loadRawData(e:MouseEvent):void {
                          var ro:RemoteObject = new RemoteObject();
                          ro.source = 'cfcs.DataTest.PropertiesService';
                          ro.destination = 'ColdFusion';
                          
                          ro.addEventListener( ResultEvent.RESULT, onRawDataResult );
                          ro.addEventListener( FaultEvent.FAULT, onRawDataFault );
                          ro.getAllProperties();
                     }
      

       

      Flex loads all of the data as it is suppose to except for the tenants. The debugger writes out a message saying that i would not convert []@ea36699 to mx.collections.ArrayCollection. I have also tried this with an ORM generator in ColdFusion Builder and then adding the service through Data/Services panel within Flash Builder. Tried to Right-click - Test Operation on getAllProperties():Properties[] the test succeeds and everything works fine.

       

      It might be something really really small that i am missing but i cannot figure it out Please help! thanks in advance!

        • 1. Re: CF9 ORM Relational Mapping + Flash Builder 4 nested value objects errors
          rewheaton

          I struggled with this for hours a few weeks back.  Add the attribute remotingfetch="true" to your relationship like this:

           

          <cfproperty name="Tenants"
                              fieldtype="one-to-many"
                              singularname="Tenant"
                              cfc="Tenants"
                              mappedby="Tenants"
                              fkcolumn="TenantID"
                              remotingfetch="true"
                              lazy="false"
                              type="array"
                                          <!--- can be array or struct ---> 
                              <!---structkeytype="int" structkeycolumn="ID"--->
                              />

           

           

          Hope this helps!