No announcement yet.

Add Fields to an Entity in Code

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    Hi m.mayer,

    Hope, this thread will be helpful:


    • #3
      If you are not familiar with the Entity Manager I recommend that you read this as well:


      • #4
        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.


        • #5
          Hi m.mayer,

          In this case, that article may come in handy:


          • #6
            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...


            • #7
              You can try to duplicate how fields are created in the Admin GUI, check this link


              • #8
                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.


                • m.mayer
                  m.mayer commented
                  Editing a comment
                  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.