Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Proper DataSource descriptor for composed entity from other DataSource?

    Greetings,

    I have the following server-side data model:

    Code:
    ----------------------
    | A                  |
    |--------------------|
    | Long id <PK>       |
    | String foo         |
    | String bar         |
    | B mostRecentB      |
    ----------------------
    
    ------------------
    | B              |
    |----------------|
    | Long id <PK>   |
    | String text    |
    | Date timestamp |
    ------------------
    I'm trying to build a UI where I have a ListGrid for As. It shows A's standard fields, along with "mostRecentB.text". The A ListGrid "canExpandRecords", and in the expansion I want a nested B ListGrid for the full history of all Bs for the given A.

    I want to allow the user to add a new B via the A ListGrid. The id and timestamp can be generated server-side, so the user would simply be presented with an inline text field for B.text in the related cell. Upon submit I want both the A and B ListGrids to update accordingly.

    I also want the user to be able to add a new B via the nested B ListGrid, and again the associated A.mostRecentB.text in the A ListGrid needs to be updated in the UI when this happens.

    I have an A custom DataSource for the A ListGrid:

    Code:
    <DataSource ID="ADataSource" serverConstructor="spring:aDataSource"
    	schemaBean="com.mycompany.A">
    	<fields>
    		<!-- Not sure if this is necessary with autoDeriveSchema?... -->
    		<field primaryKey="true" name="id" />
    	</fields>
    </DataSource>
    And a B custom DataSource for the B ListGrid:

    Code:
    <DataSource ID="BDataSource" serverConstructor="spring:bDataSource"
    	schemaBean="com.mycompany.B">
    	<fields>
    		<field primaryKey="true" name="id" />
    	</fields>
    </DataSource>
    My understanding for adding a new B via the B ListGrid is that I would ensure A.mostRecentB is updated by way of a server-side call to dsResponse.addRelatedUpdate.

    My question is what is the best way to specify the A DataSource descriptor for A.mostRecentB? Would I be better off to add a "String mostRecentBText" to my A model, and map that instead of the entire mostRecentB entity? With this approach I presume I would again need to use dsResponse.addRelatedUpdate server-side to update the B DataSource.

    Alternatively should I use foreignKey to associate A.mostRecentB with the B DataSource? If so how would that look with mostRecentB being a composed entity? Would it work if B had a composite primary key (in 8.3)?

    Thanks,

    Ian


    SmartClient Version: v8.2p_2012-06-06/Pro Deployment (built 2012-06-06).

    #2
    Yes, you need to declare the mostRecentB field in the DataSource, otherwise, even if you declare it in the ListGrid, attempts to save to it would be rejected by the server.

    As far as how to populate it, add an operationBinding for a varation on operationType "fetch" for DataSource A, and in that DMI, add in the data from DataSource B.

    If your custom DataSource extended from SQLDataSource, it would be easy enough to do this with SQL Templating, but presumably you've got some other kind of system - you'll need to figure out how to do the equivalent of a SQL join + max() in that system.

    Comment

    Working...
    X