Error 500 No 'foreignMidKey'
Collapse
X
-
hey Bertomi
It is easy to achieve such thing using formula. i assume that when a material entity is changed (updated) you wanted to update all its related orders entities (mainly the field number) correct? if yes this is how you can achieve it using formula:
Please keep in mind that you need to change things to their correct name like the name of the link between material and orders (i assumed it is orders).PHP Code:// Trigger this when the name is changed and entity is not new - only when updated
ifThen(!entity\isNew() && entity\isAttributeChanged('name'),
// Get the count for next function record\findRelatedMany()
$count = record\count('Order', 'materialId=', id);
// Fetch all related orders for current material entity
$relatedOrders = record\findRelatedMany('Material', id, 'orders', $count, 'createdAt', 'desc');
$i = 0;
// Loop through the orders and update the number field as you wish
while(
$i < array\length($relatedOrders),
(
// just as example will loop through all related orders and update number field to 127.
record\update('Order', array\at($relatedOrders, $i), 'number', 127);
$i = $i + 1;
)
);
)
Hope this helpsLeave a comment:
-
Paulina
Dear Paulina. Can I ask you for a little help?
I have two custom entities. One is called materials, the other is called order. Materials have a one-to-many relationship with the order. There is a number field in the order entities, the value of which I would like to add to the value in the same number field of the related materials entity when the record is updated. Unfortunately, I can't do it using a formula. If you could help me, I would be very grateful.
Thanks ThomasLeave a comment:
-
Bertomi,
It seems that you have deleted some relationship (or deleted and created a similar one, and the fields in Layouts remained from the old relationship).
- Try to remove the relationship connecting these entities.
- Remove all interconnected fields between them from all Layouts (especially from Layouts -> Search Filters) and from the Entity Manager (pay special attention to fields with the Foreign type).
- Make Rebuild.
- Recreate the relationships and required fields, make Rebuild again.Leave a comment:
-
Hi Victor.
Thanks to reply.
Yes, I tried rebuilding and hard rebuilding as well. Unfortunately, it didn't help. In the LOG, there are only the two lines below, which I don't think are related to this problem. Unfortunately, I haven't found a solution yet. The error occurs when applying a filter field to the entity.
I am attaching the contents of the LOG.
[2023-04-24 02:02:02] ERROR: Uncaught Exception PDOException: "SQLSTATE[HY000] [2002] No such file or directory" at /volume1/web/myespo/application/Espo/ORM/PDO/MysqlPDOFactory.php line 73 {"exception":"[object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /volume1/web/myespo/application/Espo/ORM/PDO/MysqlPDOFactory.php:73)"}
[2023-04-24 02:03:01] ERROR: Uncaught Exception PDOException: "SQLSTATE[HY000] [2002] No such file or directory" at /volume1/web/myespo/application/Espo/ORM/PDO/MysqlPDOFactory.php line 73 {"exception":"[object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /volume1/web/myespo/application/Espo/ORM/PDO/MysqlPDOFactory.php:73)"}

Leave a comment: