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?
Announcement
Collapse
No announcement yet.
What are the difference between fields and attributes?
Collapse
X
-
-
Comment
-
I see $call->get('parent') returns the entity instead of [parentId, parentType and parentName]. Does it work like that for all link types?
-
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.
-
-
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
-
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...
-
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;
}
Comment