Custom Database Views

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • SoBeGuy
    replied
    yuri Thank you!

    Leave a comment:


  • yuri
    replied
    You can also create a collection from an SQL: https://github.com/espocrm/espocrm/b...actory.php#L58

    All column names in an SQL result should correspond to entity attribute names.

    IMPORTANT: Beware of a possible SQL injection vulnerability. Better to avoid using raw SQLs at all.
    Last edited by yuri; 08-25-2024, 07:11 AM.

    Leave a comment:


  • yuri
    commented on 's reply
    You will get PDOStatement. Then you can run fetch or fetchAll on it. You will get array data (not Entity).

  • yuri
    replied
    You can use SqlExecutor https://github.com/espocrm/espocrm/b...nager.php#L423. The source code is documented and type hinted, it can be used w/o a separate documentation.

    Leave a comment:


  • SoBeGuy
    replied
    dimyy, selectBySql sounds like exactly what I'm looking for. However, I can't find any information about this in the documentation. Can you point me in the right direction?

    Leave a comment:


  • dimyy
    replied
    It's not good idea replacing tables, bicose any rebuild corrupt this construction. May be you should look to selectBySql / createFromSql ? It ssems more applicable

    Leave a comment:


  • SoBeGuy
    started a topic Custom Database Views

    Custom Database Views

    I need to create a view in MySQL that can be accessed as a readonly entity in Espo. The view definition is extremely complex and cannot be created using Espo's filters. Is there any built-in functionality for this? If not, what would be the best approach? I imagine I could create an entity in Espo containing the same fields as the view, then replace the entity's table in the database with a view of the same name. From Espo's perspective, it would look like a regular table but the records would be populated dynamically. Is this correct, or is there a better way to accomplish this?
Working...