Announcement

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

    Delete Attribute from Record

    SmartClient Version: SNAPSHOT_v9.0d_2012-11-15/PowerEdition Deployment (built 2012-11-15)

    I have a Record created from a fetch over several joined SQL tables.

    I want to update another table with a portion of this Record but the source record contains fields not present in this update table.

    I realize I can write a new Datasource to match the fields of the update table and then do an update operation of the original Record.

    But in order to save creating yet another Datasource is there a simple method of deleting attributes from a copy of the Record?

    If I define an OperationId for this target update in the original Datasource, how can I create a value clause (?) to limit the updates to a subset of fields of the attributes of the Record?

    I suppose I could also convert the Record to a Map, and remove unwanted attributes from the Map, and then recreate a new Record from this modified Map.

    But I just want to ask if there is a simple way of deleting Attributes from a single Record, or restricting the values used in the Update within a Datasource OperationId before I go with the alternatives I've suggested.

    I don't see a way through the API for the Record Class.

    #2
    Well, it's straightforward to strip unwanted attributes from a Record. For example, if you had the databound ListGrid myListGrid, you could define a function addStrippedRecord() as follows:

    Code:
    void addStrippedRecord(Record newRecord) {
        Record r0 = myListGrid.getRecord(0);
        Record strippedRecord = Record.copyAttributes(newRecord, r0.getAttributes());
        myListGrid.addData(strippedRecord);
    }
    Any record from the DataSource you want to update could be used to filter the new record - I chose the first record of the ListGrid for simplicity.

    Comment


      #3
      Thanks for the advice, I may make use of it.

      However I think you have offered me the inverse solution to my needs.

      I have a record with 20+ attributes. I have a known small set (3-4) of attributes I want to remove, and I have an unknown set of attributes I want to use in the Update.

      Your solution, I believe, assumes I know the set of attributes required in the update. I don't. I only know the small set I want to remove.

      I will move ahead with using a Record->Map->Record transformation, unless you have a better suggestion.

      Comment


        #4
        Also, have you tried just updating the more sparse DataSource with the more dense Record? With an SQLDataSource, I would expect it to just quietly drop any record properties that are not applicable to the DataSource.

        Comment


          #5
          Yes that's how I exactly started out and it works for 90% of the cases, but there are always 3 or 4 fields/attributes I need to delete from the record before doing the update using this 'generic' datasource. .

          I'm trying to avoid the case where I have to have a unique datasource matching each target update table, and where the record properties would be correctly dropped.

          It saves me writing an extra 40 or 50 datasources...

          Comment

          Working...
          X