Options

Master - Detail relationship without composite keys

a_developera_developer Member Posts: 20
Hi I am new in Navision and I would like to implement the master-detail relational model without having composite keys. To be more specific

In a relational DB a master detail relation example:
Table[Person]
Person_ID (PK)
Person_name
Person_surname

Table[Lockers]
Locker_ID (PK)
Locker_Name
Person_ID

I want to make a form that displays Person and has a subform that displays the Lockers of that person. So far I have found two ways:

1. make a subform with subformlink (Person_ID=FIELD(Person_ID)) but then I have to create a compound key (Locker_ID, Person_ID). This is something I do not want (because I will have to create two fields in every other table that links to Lockers).

2. I can notify the subform (by calling one of its methods) when a new Record is created OR when record navigation happens but I have to write too much trigger code which is a pain.

Do you have a work around?



Thanks

Comments

  • Options
    kinekine Member Posts: 12,562
    If you want all lockers for the person you must use subformlink (Person_ID=FIELD(Person_ID)) - because Person_ID is the connection between the two tables... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    a_developera_developer Member Posts: 20
    You are right sorry (error in the example). But the problem remains
  • Options
    kinekine Member Posts: 12,562
    I do not understand you- where is problem? You do not need to extend your primary key - the tables as you defined are ok and sufficient for you... (you only add secondary key for Person_ID for faster access)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    a_developera_developer Member Posts: 20
    It works for viewing. If I try to insert a new Locker then it will be inserted in the Locker table with LockerID of 0 (and of course the line disapears from the subform).
  • Options
    kinekine Member Posts: 12,562
    See property PopulateAllFields on the Subform form...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    a_developera_developer Member Posts: 20
    Tried it, does not work. Even though the SubFormlink is set correctly (I know that because the display only works)and it should act as a filter for the PopulateAllFields, still the new records go with an ID of 0.

    I belive this is partly because I suck at navision. :)

    Could you please send me a fob that does the Person, Locker example?

    Super thanks
  • Options
    kinekine Member Posts: 12,562
    I'll try but I am out of my office now... may be tomorrow morning...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kinekine Member Posts: 12,562
    Solution sent into your PM...

    Notice the property DellayedInsert and PopulateAllFields on the subform.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    a_developera_developer Member Posts: 20
    Thanks a ton!

    The strange thing was that while your solution worked, my form did not. Even though I had the exact same properties as the ones you told me to use on the previous posts. Then another developer hint me to delete my form and create it again....and it worked!

    thank you for your help again
Sign In or Register to comment.