Announcement

Collapse
No announcement yet.

Display a link from an existing link relation

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

  • Display a link from an existing link relation

    Hello,

    Let's say we have EntityA, EntityB and another EntityC. How do I create a notStorable field link to EntityC in EntityA so that it can be displayed and sorted in list view. (Assume I define a loader to set its id and name).

    Custom/Resources/metadata/entityDefs/EntityA.json

    Code:
    {
        "fields": {​
            "entityB": {
            "type": "link",
            "isCustom":true,
        },​
        "links": {
            "entityB": {
                "type": "belongsTo",
                "foreign": "entityAs",
                "entity": "EntityB",
                "isCustom": true
            },​
        }
    },

    Custom/Resources/metadata/entifyDefs/EntityB.json

    Code:
    {
        "fields": {​
            "entityAs": {
                "type": "linkMultiple",
               "isCustom":true,
            },​
            "entityC": {
                "type": "link",
                "isCustom": true,
            },​
        },
        "links": {
            "entityAs": {
                "type": "hasMany",
                 "foreign": "entityB",
                 "entity": "EntityA",
                 "isCustom": true
            },​
            "entityC": {
                "type": "belongsTo",
                 "foreign": "entityBs",
                 "entity": "EntityC",
                "isCustom": true
            },​
        }
    }








  • #2
    hey czcpf

    If you have the relationship set already between entityC and entityA then you can take advantage of foreign fields which are not sortable by default, e.g you can do something like below:

    PHP Code:
    {
        
    "fields":{
            
    "entityB": {
                    
    "readOnly"true,
                    
    "type""foreign",
                    
    "link""entityB",
                    
    "field""name",
                    
    "view""views/fields/foreign-varchar"// you an even create your own custom view
                    
    "notStorable"true
                
    }
        },

        
    "links": {
            
    "entityB": {
                
    "type""belongsTo",
                
    "entity""EntityB",
                
    "foreign""entityAs"
            
    },
        }
    }
    ​ 
    Rabii
    Web Dev

    Comment


    • czcpf
      czcpf commented
      Editing a comment
      Thats the issue though. There is no existing relationship between entityA and entityC. The relationship goes like entityA->entityB-entityC. So entityA has a single link to entityB && entityB has a single link to entityC. I want to create a readOnly, notStorable field for entityC in entityA. Espo doesn't seem to allow you to create a foreign field to a link in the foreign entity.

    • rabii
      rabii commented
      Editing a comment
      I don't think it would be possible, because this set up should represent a relationship between the entities otherwise there could be no link. i suggest that you create a relationship (readonly) between entityA and entityC, unless if you want to customise how relationships work in espo and add your own something like hasOneThrough or hasManayThrough.

      Personnaly i would just add that relationship and set it up as a readOnly link and maybe use formula or hooks to wire it all up.

    • czcpf
      czcpf commented
      Editing a comment
      Thanks. How do you create a readonly relationship?

  • #3
    Hey

    You can try something as below, create a relationship between entityA and entityC as below, then use formula on entityB so that when the field relationship of entityC is changed then update it on entityA, i think the structure below would allow to use a notsortable link between the two entities:

    PHP Code:
    (entityAOne-to-One Left (entityC)

    {
        
    "fields": {
            
    "entityCField": {
                
    "type""linkOne",
                
    "readOnly"true,
                
    "notStorable"true,
                
    "view""views/fields/link-one"
            
    }
        },

        
    "links": {
            
    "entityCField": {
                
    "type""hasOne",
                
    "entity""entityC",
                
    "foreign""entityAField"
            
    },
        }
    }


    (
    entityCOne-to-One Right (entityA)

    {
        
    "fields": {
            
    "entityAField": {
                
    "type""link",
                
    "layoutDetailDisabled"true
            
    }
        },

        
    "links": {
            
    "entityAField": {
                
    "type""belongsTo",
                
    "entity""entityA",
                
    "foreign""entityCField"
            
    },
        }
    }
    ​ 

    This should work and it would set the link as a notSortable.

    I hope this helps, sorry couldn't come with proper name fields but just used entity like field name.
    Rabii
    Web Dev

    Comment

    Working...
    X