Jump to content
Jihene Heni

Create Table association betwenn tab1 and tab2

Recommended Posts

Hi ,

I want to  create a table association between two tables in Module Installation Prestashop 1.7

I tried this code in module installation: 

   

public function install()
   {

    if (Shop::isFeatureActive())
     Shop::setContext(Shop::CONTEXT_ALL);

   $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tab3` (
 id_a INT(10) NOT NULL,
   id_b INT (10) NOT NULL,

CONSTRAINT pk_asso PRIMARY KEY ( id_a, id_b ) ,
CONSTRAINT fk_asso2 FOREIGN KEY ( id_a ) REFERENCES ps_tab1( id_tab1)

),
CONSTRAINT fk_asso1 FOREIGN KEY ( id_b ) REFERENCES ps_tab2( id_tab2) ,

) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';

  if(!$result=Db::getInstance()->Execute($sql))
   return false;

    return parent::install() &&
     $this->registerHook('leftColumn') &&
     $this->registerHook('header') &&
     Configuration::updateValue('MYMODULE_NAME', 'my friend');

   }

it does'nt work

 

  

   

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More