Announcement

Collapse
No announcement yet.

Add Fields to an Entity in Code

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

  • m.mayer
    commented on 's reply
    I know that this way of changing the database isn't very conventional.
    However in this case i just need to create Boolean Flags for every line of data i get from a third party API.
    I understand your concern, it's just a very specific requirement we have for our current project.

  • item
    replied
    strange request...
    A database must be under control (security, integrity, conception, design,...).. i can't imagine give the opportunuity to a API to create field and so in database.
    for me, you have :

    if (!$entity->hasAttribute($value)) reject all ! create task and assign to someOne.

    And what about rebuild ?
    And what about reserved word .. in espoCRM, in database ..
    And what about camelCase ?

    it's just my opinion
    Last edited by item; 10-19-2021, 05:53 PM.

    Leave a comment:


  • telecastg
    replied
    You can try to duplicate how fields are created in the Admin GUI, check this link https://github.com/espocrm/espocrm/b...eldManager.php

    Leave a comment:


  • m.mayer
    replied
    I took a quick look into your suggested thread. It seems i could potentially create and alter Entity Field definitions by appending the metadata .json File. As i see it however there is no clean way of adding a Field to an Entity in PHP Code itself.

    Ideally i am looking for something like this:
    PHP Code:
    $entityManager $this->getEntityManager();
    $entityManager->getRepository($enitity)->addField("int""counter", {options}) 
    In this case the options would specify something like: default Value, Disable InLine editing, etc...

    Leave a comment:


  • Vadym
    replied
    Hi m.mayer,

    In this case, that article may come in handy:

    Leave a comment:


  • m.mayer
    replied
    Sorry, i meant the Entity Manger in PHP Code. I am familiar with creating Fields in the GUI. I also know how to read and write data with the PHP Entity Manager. I had the impression there was a possibility to create Fields via PHP Code for a specific Entity.
    I need to update the Fields of a specific Entity according to a third party API.

    Leave a comment:


  • telecastg
    replied
    If you are not familiar with the Entity Manager I recommend that you read this as well: https://docs.espocrm.com/administration/entity-manager/

    Leave a comment:


  • Vadym
    replied
    Hi m.mayer,

    Hope, this thread will be helpful:

    Leave a comment:


  • m.mayer
    started a topic Add Fields to an Entity in Code

    Add Fields to an Entity in Code

    Is there a way to add Fields to an Entity via the Entity Manager. I think i saw documentation about this somewhere. I can't seem to find it right now though. I could be mistaken as well.
Working...
X