What are the difference between fields and attributes?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tothewine
    Active Community Member
    • Jan 2018
    • 373

    What are the difference between fields and attributes?

    Are they the same? In formula i see the 'add attribute' and it does not contain the entity id. The Entity Manager in the settings does not mention 'attributes' anywhere. In the php API there are 'getAttribute' and 'hasField'. Are they different?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Yes. https://github.com/espocrm/documenta...a.md#attribute
    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

    • yuri
      Member
      • Mar 2014
      • 8440

      #3
      There can be legacy methods in code base. hasField is a deprecated method.
      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

      • tothewine
        Active Community Member
        • Jan 2018
        • 373

        #4
        If I want to get a value from entity I do $entity->get('value') and i'm good unless it's a link?

        Comment


        • tothewine
          tothewine commented
          Editing a comment
          I see $call->get('parent') returns the entity instead of [parentId, parentType and parentName]. Does it work like that for all link types?

        • telecastg
          telecastg commented
          Editing a comment
          I've not used $entity->get('parent') but my experience is calling $entity->get('parentId') or $entity->get('parentType')

          For child-parent links Espo creates a two columns (fields) in the database table of "child", one is called 'parent_type' and the other one is 'parent_id' so they can be called in ORM as 'parentId' and 'parentType' respectively.

          For one-to-many links, the 'one' entity table has a column '{many_id}' for each different 'many' entitties.

          For example, I have a 'tenancy' entity that can have many 'serviceTickets' linked to it, so the 'service_ticket' table contains a column 'tenancy_id' thus in ORM if I want to know the tenancyId of a ticket I use $ticket->get('tenancyId') then with that information I can retrieve the 'tenancy' entity if I want.

        • tothewine
          tothewine commented
          Editing a comment
          Yeah I noticed that behavior accidentally, so I was asking. I usually do as you said...
          Last edited by tothewine; 05-21-2019, 09:47 PM.
      • tothewine
        Active Community Member
        • Jan 2018
        • 373

        #5
        I see $call->get('parent') returns the entity instead of [parentId, parentType and parentName]. Does it work like that for all link types? For example #->get('assignedUser') returns null.
        Also, is it safe to use $entity->hasRelation('whatever') to check if the entity is related to something?


        $call->get('parent')->get('cap')->hasRelation('assignedUser'); --> true
        $call->get('parent')->get('cap')->get('assignedUser'); --> null

        Comment


        • telecastg
          telecastg commented
          Editing a comment
          try $call->get('parent')->get('cap')->get('assignedUserId'); that should return the assignedUser id value

        • tothewine
          tothewine commented
          Editing a comment
          What I meant here is that get('parent') returns an entity object, while get('assignedUser') doesn't: how can I test if 'get' cannot be used to obtain the entity?
          I think I should read more about the field definitions in the metadata of entities...

        • telecastg
          telecastg commented
          Editing a comment
          From application/Espo/ORM/Entity.php

          public function get($name, $params = [])
          {
          if ($name == 'id') {
          return $this->id;
          }
          $method = '_get' . ucfirst($name);
          if (method_exists($this, $method)) {
          return $this->$method();
          }

          if ($this->hasAttribute($name) && isset($this->valuesContainer[$name])) {
          return $this->valuesContainer[$name];
          }

          if ($this->hasRelation($name) && $this->id) {
          $value = $this->entityManager->getRepository($this->getEntityType())->findRelated($this, $name, $params);
          return $value;
          }

          return null;
          }
      Working...