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;
}
What are the difference between fields and attributes?
Collapse
X
-
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 -
If I want to get a value from entity I do $entity->get('value') and i'm good unless it's a link?Leave a comment:
-
There can be legacy methods in code base. hasField is a deprecated method.Leave a comment:
-
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?Tags: None
Leave a comment: