Announcement

Collapse
No announcement yet.

One to one relationship not enforced

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • One to one relationship not enforced

    Hi Devs,

    I have two entities, Camera and Lens. There is a 'current lens' relationship between the two which is one to one.

    Click image for larger version

Name:	lenscamrel.png
Views:	155
Size:	58.7 KB
ID:	99711

    I expected that relationship would restrict a lens from being related to more than one camera at the same time, however Espo is letting me do that, eg:

    Click image for larger version

Name:	samelens.png
Views:	132
Size:	27.5 KB
ID:	99712

    I'm not sure if I've set it up right. Does Espo enforce a one to one relationship out of the box, or do I need to enforce the relationship programmatically?

    Cheers,
    Clare





  • #2
    Hi,

    How did you link the records? Did you do it via the UI, by custom code, workflow or formula? It's supposed to be impossible to have this condition when using the UI. But maybe there's some bug.

    Comment


    • #3
      Hi Yuri,

      I did it via the UI on a fresh install of version 7.5.5. I just retested it with new entities with a one to one relationship and I'm getting the same behaviour.

      Cheers,
      Clare

      Comment


      • #4
        Actually, Yuri there is a bit more to it than I originally thought - it's letting me create the relationship as described above, but it is not saving it in the database and when I refresh the page, the second relationship is gone.

        After refreshing the page:

        Click image for larger version

Name:	cam-lens-refresh.png
Views:	137
Size:	21.0 KB
ID:	99746

        In the DB:

        Click image for larger version

Name:	lens-table.png
Views:	111
Size:	34.1 KB
ID:	99747

        But the front end still lets me attach lens 1 even though it's already associated with cam 2:

        Click image for larger version

Name:	lens-select.png
Views:	114
Size:	37.7 KB
ID:	99748

        There are no errors in the log or the browser console.

        Cheers,
        Clare

        Comment


        • #5
          Hi Clare,

          When you link the same record, an existing link is removed. If you do it from the list view, the current record is refreshed, but the whole list is not. Hence, you see another record with the previous link.

          As a workaround, you can write a simple API Before-Save script that will check whether another record with the same link exists and throw exception if yes.

          Comment


          • #6
            Thanks Yuri, got it, it's pretty much doing what it should except that it's not refreshing the view. I will try the before save script.

            Comment

            Working...
            X