Menu

Filtering on link N:N

2024-08-26
2024-08-27
  • razsalgul1635

    razsalgul1635 - 2024-08-26

    Hello,

    in my custom extension I have link lets say "lnkObject1ToObject2".
    <fields>
    <field id="Object1_id" xsi:type="AttributeExternalKey">
    <sql>object1_id</sql>
    <target_class>Object1</target_class>
    <is_null_allowed>false</is_null_allowed>
    <on_target_delete>DEL_AUTO</on_target_delete>
    <jointype>
    </jointype></field>
    <field id="Object2_id" xsi:type="AttributeExternalKey">
    <sql>object2_id</sql>
    <target_class>Object2</target_class>
    <is_null_allowed>false</is_null_allowed>
    <on_target_delete>DEL_AUTO</on_target_delete>
    <jointype>
    </jointype></field>
    </fields>

    When enduser is creating this link he pics object 1. Then I want for him to choose from limited ammount of object2.
    (via filters in
    <field id="Object2_id" xsi:type="AttributeExternalKey">
    <filter><![CDATA[SELECT)... ]]></filter>
    )
    The limitation in question is from another link "lnkObject1ToObject3" where is object2 linked via "lnkObject3ToObject2".</field>

    To the filter I want to display all objects2 that are linked on object3 which is then linked to object1.

    Is it possible to come up with filter that can meet these criteria? (Im unable to write condition in that filter)

    If its not possible to write can be fields:
    <field id="Object1_id" xsi:type="AttributeExternalKey"> and
    <field id="Object2_id" xsi:type="AttributeExternalKey">
    from "lnkObject1ToObject2" pre-filled from SQL table or view?</field></field>

    Thank you for help!

     
  • Vincent @ Combodo

    You are not very precise about which filter you want, but it should be possible to follow the links, and if your logic is to say that Object1 can be linked to Object2 only if there is an Object3 which link them already, then this should do the work:

    Filter of <field id="object2_id" xsi:type="AttributeExternalKey"></field>

    SELECT Object2 AS O2
    JOIN lnkObject3ToObject2 AS L32 ON L32.oject2_id=O2.id
    JOIN Object3 AS O3 ON L32.oject3_id=O3.id
    JOIN lnkObject1ToObject3 AS L13 ON L13.oject3_id=O3.id
    WHERE L13.object1_id=:object1_id

     
    • razsalgul1635

      razsalgul1635 - 2024-08-27

      Thank you very much it worked!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.