EntityDefs and links

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • caffeine
    Member
    • Aug 2014
    • 48

    EntityDefs and links

    Hi, I'm having some problems with my custom module, I have 2 entities: Article and ArticleControl with this definitions:

    Article:
    PHP Code:
    {
        "fields": {
            "name": {
                "type": "varchar",
                "required": true
            },
            "createdAt": {
                "type": "datetime",
                "readOnly": true
            },
            "modifiedAt": {
                "type": "datetime",
                "readOnly": true
            },
            "createdBy": {
                "type": "link",
                "readOnly": true
            },
            "modifiedBy": {
                "type": "link",
                "readOnly": true
            },
            "assignedUser": {
                "type": "link",
                "required": true
            },
            "teams": {
                "type": "linkMultiple"
            }
        },
        "links": {
            "createdBy": {
                "type": "belongsTo",
                "entity": "User"
            },
            "modifiedBy": {
                "type": "belongsTo",
                "entity": "User"
            },
            "assignedUser": {
                "type": "belongsTo",
                "entity": "User"
            },
            "teams": {
                "type": "hasMany",
                "entity": "Team",
                "relationName": "EntityTeam"
            },
            "tasks": {
                "type": "belongsTo",
                "entity": "Task"
            },
            "control": {
                "type": "hasChildren",
                "entity": "ArticleControl",
                "foreign": "parent"
            }
        },
        "collection": {
            "sortBy": "name",
            "asc": false,
            "boolFilters": ["onlyMy"]
        }
    } 
    
    ArticleControl:
    PHP Code:
    {
        "fields": {
            "data": {
                "type": "text"
            },
            "status": {
                "type": "enum",
                "options": ["Pending", "Completed"],
                "default": "Pending"
            },
            "createdAt": {
                "type": "datetime",
                "readOnly": true
            }
        },
        "links": {
            "control": {
                "type": "belongsTo",
                "entity": "Article"
            }
        },
        "collection": {
            "sortBy": "createdAt",
            "asc": false
        }
    } 
    

    The issue is when I call /Article/%ID%/control I always get all the items instead of the items connected. What I'm missing?

    Thanks
    Last edited by caffeine; 09-28-2014, 07:34 PM.
  • yuri
    Member
    • Mar 2014
    • 8627

    #2
    Hi

    In Article you should have:

    PHP Code:
            "controls": {
                "type": "hasMany",
                "entity": "ArticleControl",
                "foreign": "article"
            } 
    
    In ArticleControl

    PHP Code:
            "article": {
                "type": "belongsTo",
                "entity": "Article",
                "foreign": "controls"
            } 
    
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • caffeine
      Member
      • Aug 2014
      • 48

      #3
      Uff Thanks!!!!! it's working now.

      Comment

      Working...