3 Replies Latest reply on Oct 24, 2006 5:57 PM by T._Ruggles

    FDS relationship question

    World_Traveler
      Hello,

      This is a big time FDS newbie question.

      I have developed my first Flex2 app using RemoteObjects to ColdFusion. I'm satisfied but I now understand how FDS could help me better (mainly in the sync/conflict area).

      But there is something, I'm sure quite easy, that stumps me when I study FDS. How to use data relationships. Let me give you and example:

      A datagrid contains

      Order_No Customer_Name Warehouse_Name Date Total
      ------------- ----------------------- -------------------------- -------- --------

      The customer_name comes from the Customer table where Order.No_Customer = Customer.No_Customer. Same concept for Warehouse name.

      I understand that I can use LabelFunction to get the name but I am not convinced that returning to the database a hundred times to get each customer and warehouse name is wise. (I may be wrong).

      In my RemoteObjet application I prepared a SQL query in a CFC to pre-prepare the data to fill the grid and load the order as per the order_no column.

      If I run such a query in FDS (if possible) I will loose the fiil/sync capabilities I want to use, at least I think.

      But how can I accomplish that in FDS ?? In other language/technologies (read WebObjects) I could use "Pathing" like order.toClient().name. Is there something like that in Flex/FDS ?

      Our database is pretty well layed out from a relational standpoint. So solving this issue will help me a lot.

      Thanks

      Steve




        • 1. Re: FDS relationship question
          T._Ruggles Level 1
          Hi Steve,

          I'm not entirely sure that I understand where your questions lie. But here's some info.

          For FDS using the Java Adapter alone you would write a Java assembler class whose purpose is to respond to messages that request fills (for which you could have many different options), get single items by identity and data updates.

          Your fill methods can load up data lists in any manner which you see fit and with any params that you need. There are two ways to accomplish this:
          - extend the AbstractAssembler class and just check the arg list that gets passed into your fill method via reflection to determine how the fill should be serviced
          - do not extend AbstractAssembler but instead specify all of your fill method variations in your destination definiition.

          As for the schema - you probably want to take advantage of nested collections / relationships and lazy loading. I picture the Java version of your objects looking something like this:

          Order
          -----
          order_no
          date
          total
          Customer
          Warehouse

          Customer
          --------
          customer_no
          customer_name
          customer_phone
          ...

          Warehouse
          ---------
          warehouse_no
          warehouse_name
          warehouse_phone
          ...

          Your destinations might look like this (not using AbstractAssembler):

          <destination adapter="java-adapter" id="Orders">
          <properties>
          <source>foo.bar.OrderAssembler</source>
          <item-class>foo.bar.Order</item-class>
          <scope>application</scope>

          <metadata>
          <identity property="order_no"/>
          <many-to-one destination="Customers" property="customer" lazy="true" />
          <many-to-one destination="Warehouses" property="warehouse" lazy="true" />
          </metadata>

          <server>
          <fill-method>
          <name>getOrders</name>
          </fill-method>

          <fill-method>
          <name>getOrdersByCustomerNumber</name>
          <params>int</params>
          </fill-method>

          <sync-method>
          <name>syncPlayers</name>
          </sync-method>

          <get-method>
          <name>getOrder</name>
          </get-method>

          <count-method>
          <!-- Count all -->
          <name>count</name>
          </count-method>

          <count-method>
          <!-- Count by customer number -->
          <name>count</name>
          <params>int</params>
          </count-method>

          </server>
          </properties>
          </destination>



          <destination adapter="java-adapter" id="Customers">
          <properties>
          <source>foo.bar.CustomerAssembler</source>
          <item-class>foo.bar.Customer</item-class>
          <scope>application</scope>

          <metadata>
          <identity property="customer_no"/>
          </metadata>
          ....
          </properties>
          </destination>


          <destination adapter="java-adapter" id="Warehouses">
          <properties>
          <source>foo.bar.WarehouseAssembler</source>
          <item-class>foo.bar.Warehouse</item-class>
          <scope>application</scope>

          <metadata>
          <identity property="warehouse_no"/>
          </metadata>
          ....
          </properties>
          </destination>


          Now the fill method(s) of the OrderAssembler would be responsible for building the list of orders with the required warehouse and customer info but then any updates would be routed to their respective destination and pushed to anybody with fills that include them either directly from their destinations or via the OrderAssembler.

          Does any of this help?
          • 2. Re: FDS relationship question
            World_Traveler Level 1
            Thanks Tom,

            While it was not exactly what I was looking your explanation got me onto something and I found what I needed (Managed Associations !!!). I now have a working example here !!

            I'm down to one little thing !!

            How can I use Managed Associations in a DataGrid ?.

            I want to show the Customer Name in the grid, not the customer number !!

            I tried to use the label function with no luck

            the DataField with {order.Customer.Name} without success.

            Suggestions are welcome !!

            Thanks !!

            Steve
            • 3. Re: FDS relationship question
              T._Ruggles Level 1
              DataField won't work but labelFunction is exactly what you need. You might try using mx.utils.ObjectUtil.toString(item) in your label function to see exactly what the object looks like. This should help.