Results 1 to 4 of 4

Thread: [Answers] Relationship

Threaded View

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Relationship

    I should also add to this that when a new record is "inserted" into the "suppliers" table, Lianja will automatically use the parent key and assign the primary key into the suppliers (child) to maintain the relationship.



    Q:
    How can I relate 2 sections on more than 1 field ?
    orders!ordernumber+orders!subordernumber to financ!ordernumber+financ!subordernumber
    i.o.w. can I change the relation that's made automaticly or do I have to set relation by code?
    A:
    If you have composite keys such as in your example then Lianja is unable to insert a value in the child table to maintain the relationship when you add records.
    There are a few ways round this.
    If you look in the section attributes.
    Scroll down to "Related data"
    Uncheck the "Automatically relate" attribute.




    You can then write your own "ParentDataChanged" delegate to perform your own relationship.
    I would suggest using a "local" virtual table for the child as you can then issue a requery() on the section and specify a new SQL WHERE clause e.g.

    Code:
    // use . not ! to reference the fields in the tables.
    // asumes section is bound to the financ table and that is a VT with WHERE !=0 specified initially
    Lianja.get("page1.section2").requery("financ.ordernumber+financ.subordernumber='{orders.ordernumber+orders.subordernumber}'")
    // notice how I use {...} macros as these are substituted into the SQL command as a constant which is much faster and helps the SQL optimizer
    To solve the issue of inserting new records that maintain the parent->child relationship you need to write your own custom delegate for "Before data create". This will allow you to insert a new record specifying the component parts of the composite key.




    I would suggest looking into using Virtual Tables that have a "local" connection string which will handle these types of relationship much better. There is an example in the distribution.



    Q:
    Hi, how do I set up relations in tables with different field names e.g Supp_id and Supp_code.
    I have added
    tablename.fieldname
    in the parent and child sections in the section attribute settings but it doesnt work.
    A:
    Try removing the tablename. and just specify the fieldnames.



    Look at the grid filter example and the virtual tables example.
    section relationships flow from parent to child no matter how the sections get populated.
    any section on the same table to the grid should relate as you navigate within the grid.
    remember, the relationship manager allows relating upwards in the sections as well as downwards. The order of the sections on the page is not important.



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352
    Last edited by josipradnik; 2017-01-12 at 02:03.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us