Announcement

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

    customSelectExpression and tableAlias

    I have ds like
    Code:
    <DataSource
    schema="public"
    serverType="sql"
    dbName="DemoDatabase"
    ID="test"
    tableName="test"
    >
    <fields>
          <field name="id" type="integer" hidden="true" primaryKey="true"></field>
          <field name="f" type="integer" hidden="true"></field>
          <field name="name" customSelectExpression="case when f = 1 then 5 else 6 end" length="2147483647" type="text"></field>
    </fields>
    </DataSource>
    And i want to use this DS in other DS with fields:
    Code:
    <field name="test1_id" foreignKey="test.id"></field>
    <field name="test2_id" foreignKey="test.id"></field>
    <field name="test1_name" includeFrom="test.name" includeVia="test1_id"></field>
    <field name="test2_name" includeFrom="test.name" includeVia="test2_id"></field>
    But then SQL is incorrect, i must to add table alias to customSelectExpression, like "case when t1.f = 1 then 5 else 6 end" How I can now table alias in customSelectExpression with velocity? I try to use
    ${dataSources.test.getTableName()} but it give me real table name 'test', not it alias in query. How I can do this? Thanks
    Last edited by antipich; 21 Jun 2018, 09:01.

    #2
    See relatedTableAlias for a developer defined constant table alias. Define it on fields with foreignKey.

    Best regards
    Blama

    Comment


      #3
      It won't help
      I can set relatedTableAlias in both fields test1_id and test2_id, but customSelectExpression in other DS, and it can't now alias. I don't want to add same customSelectExpression in second DS.
      I see https://forums.smartclient.com/forum...blename-needed with same problem
      But ${dataSources.test.getTableName()} returns me real table name, not it's alias.
      Last edited by antipich; 21 Jun 2018, 09:47.

      Comment


        #4
        Adding the customSelectExpression twice like you suggested in #3 will solve the issue and is a good workaround IMHO.
        I'm the OP in the other thread, but did not test the new API, as I'm still on 11.1.

        Best regards
        Blama

        Comment


          #5
          Admins? What about new API?

          Comment


            #6
            up

            Comment

            Working...
            X