Skip to content

How I can reference default magento tables regardless the prefix?

In my schema.xml I defined a table:

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="mailing_list"
           resource="default"
           engine="innodb"
           comment="customer_group_mailing_lists">
        <column xsi:type="varchar" name="id" nullable="false" identity="true" comment="List Id" />
        <column xsi:type="int" name="customer_group_id" comment="Customer Group id to assign" />
        <column xsi:type="boolean" name="active" comment="Check if senfing to this list is active" />
        <column xsi:type="varchar" name="title" comment="Menomonic name" />

        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <constraint xsi:type="foreign"
                    referenceId="PROVINCE_PROVINCE_ID_CITY_PROVINCE_ID"
                    table="mailing_list"
                    column="customer_group_id"
                    referenceTable="customer_group"
                    referenceColumn="customer_group_id"/>
    </table>
</schema>

But beacause I want to share this module I want somehow to reference default magento tables either if a prefix is defined or not in env.php:

    'db' => [
        'table_prefix' => '',
       // Rest of settings here
    ]

So how I can reference the table customer_group regardless the prefix? I want to avoid setting user settings but instead somehow be configured on its own based the setting set upon env.php.