1

I'm trying to find out how to create relationships between tables that are created in the same modules. I create my entity with the console and I declare several tables. How can I declare shared keys in the baseFieldDefinitions of my entity and tables declared in my address_schema()

My way (is it the right method) :

my_module / address.install> address_schema ()

    'foreign keys' => [
      'lin_id' => [
        'table' => 'coo_address',
        'columns' => [
          'lin_id' => 'lin_id',
        ]
      ]
    ]

my_module / Entity> baseFieldDefinitions

$ fields ['lin_id'] = BaseFieldDefinition :: create ('integer')
      -> setLabel (t ( 'Address'))
      -> setDescription (t ('Une ligne pour l'adresse de réference.'))
      -> setSetting ('unsigned', TRUE)
      -> setDisplayOptions ('view', array (
        'label' => 'hidden',
        'weight' => 2,
      ))
      -> setDisplayOptions ('form', array (
        'type' => 'number',
        'weight' => 2,
      ))
      -> setDisplayConfigurable ('form', TRUE)
      -> setDisplayConfigurable ('view', TRUE);

I wish I had something like, but there is error. coo_address_lin being a table create in address_schema ()

$fields['lin_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Adresse'))
      ->setDescription(t('The refence of the line for the address reference.'))
      ->setSetting('target_type', 'coo_address_lin')
      ->setDefaultValue(0)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'weight' => -4,
      ])
      ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'weight' => -4,
        'settings' => [
          'match_operator' => 'CONTAINS',
          'size' => '60',
          'autocomplete_type' => 'tags',
          'placeholder' => '',
        ],
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

closed as unclear what you're asking by Jdrupal, Yusef, kiamlaluno Nov 9 at 14:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.