How do I get all table names (main table is name of entity, but what about array values, relations tables) given an entity name in a php ?
Announcement
Collapse
No announcement yet.
How do I get all database table relative to an entity type ?
Collapse
X
-
Aside from the entity name, depending on the type of link, you can have the following tables/fields:
One to Many relationship (eg: Contact -> Contract) - "contract" table will have a contact_id field
Many to Many relationship (eg: Contact -> Call) - there is a "call_contact" table containing fields "contact_id" and "call_id" linking both entities
Parent to Children (eg: Contact -> Task) - the "child" table (Task) has two fields: "parent_id" (the id of the parent Contact) and "parent_type" (the name of the parent entity, in this case "Contact")
Array values are stored as a text field in the entity as ["value1", "value2", "valueN"]
So based on the above, unless the target entity has a Many to Many relationship with another entity, there would be no additional database tables
-
thanks! btw do you know if there are any other quirks about the other relations defined here: https://github.com/espocrm/espocrm/t.../Orm/Relations ?
I was trying to do a sql backup of a single entity and all its relations
Comment
-
You're welcome
The only other quirk that I have found so far, is the Contact.title field that is not storable (does not exist as a table field), it is captured in the Contact entity but it is actually stored as "role" in the account_contact table which is the "middle" table created to implement the Many-to-Many relationship between Account and Contact that has no direct input front-end implementation.
I haven't found yet where is this precisely implemented, but unless your entity has this type of "different" field I think that you could write your sql query based on my previous comment to backup a single entity and all of its links.
You can also learn more about how metadata is converted to actual mysql tables here:
Last edited by telecastg; 02-26-2020, 06:34 AM.
- Likes 2
Comment
Comment