title: Associating an item to multiple other items (of a different class) using Prestashop's backoffice
body: <p>Having just arrived at Prestashop 1.5, I am making a very simple module: a video of the week, associated with multiple products that need to appear right next to it.</p>
  
  <p>I decided to start from the Backoffice. Right now, I can view, add, edit and remove all the Video entries but I'm a bit lost on how to map the N-N association between a video and its related products... The lack of documentation isn't helping either.</p>
  
  <p>Any ideas how to pull this off?</p>
  
  <p>Here's a bit of my code, the Video class is defined by:</p>
  
  <pre><code>class Video extends ObjectModel {
  
      public $id_video;
      public $title;
      public $url;
      public $active;
  
      public static $definition = array(
          'table'     =&gt; 'video',
          'primary'   =&gt; 'id_video',
          'multilang' =&gt; false,
          'fields' =&gt; array(
              'id_video' =&gt; array(
                  'type' =&gt; ObjectModel :: TYPE_INT
              ),
              'title' =&gt; array(
                  'type' =&gt; ObjectModel :: TYPE_STRING, 
                  'required' =&gt; true
              ),
              'url' =&gt; array(
                  'type' =&gt; ObjectModel :: TYPE_STRING, 
                  'required' =&gt; true
              ), 
              'active' =&gt; array(
                  'type'      =&gt; ObjectModel :: TYPE_BOOL, 
                  'required'  =&gt; true
              )
          ),
      );
  
  (...)
  </code></pre>
  
  <p>and the AdminVideo class is here:</p>
  
  <pre><code>class AdminVideoController extends ModuleAdminController {
  
      public function __construct()
      {
          $this-&gt;table = 'video';
          $this-&gt;className = 'Video';
          $this-&gt;lang = false;
  
          $this-&gt;fields_list['id_video'] = array(
              'title' =&gt; $this-&gt;l('ID'),
              'align' =&gt; 'center',
          );
  
          $this-&gt;fields_list['title'] = array(
              'title' =&gt; $this-&gt;l('Title'),
              'width' =&gt; 'auto'
          );
  
          $this-&gt;fields_list['url'] = array(
              'title' =&gt; $this-&gt;l('URL'),
              'width' =&gt; 'auto'
          );
  
          $this-&gt;fields_list['active'] = array(
              'title' =&gt; $this-&gt;l('Active'),
              'width' =&gt; '70',
              'align' =&gt; 'center',
              'active' =&gt; 'status',
              'type' =&gt; 'bool',
              'orderby' =&gt; false
          );
  
          parent::__construct();
      }
  
      public function postProcess()
      {
           parent::postProcess();
      }
  
      public function renderList()
      {
          $this-&gt;addRowAction('edit');
          $this-&gt;addRowAction('delete');
          $this-&gt;addRowAction('details');
  
          return parent::renderList();
      }
  
      public function renderForm()
      {
          if (!($obj = $this-&gt;loadObject(true)))
              return;
  
          $this-&gt;fields_form = array(
              'legend' =&gt; array(
                  'title' =&gt; $this-&gt;l('This weeks video'),
                  'image' =&gt; '../img/admin/world.gif'
              ),
              'input' =&gt; array(
                  array(
                      'type' =&gt; 'text',
                      'label' =&gt; $this-&gt;l('Nome'),
                      'name' =&gt; 'title',
                      'size' =&gt; 33,
                      'required' =&gt; true,
                      'desc' =&gt; $this-&gt;l('Title')
                  ),
                  array(
                        'type' =&gt; 'text',
                        'label' =&gt; $this-&gt;l('URL'),
                        'name' =&gt; 'url',
                        'size' =&gt; 33,
                        'required' =&gt; true,
                        'desc' =&gt; $this-&gt;l('Video URL')
                  ),
                  array(
                      'type' =&gt; 'radio',
                      'label' =&gt; $this-&gt;l('Active:'),
                      'name' =&gt; 'active',
                      'required' =&gt; false,
                      'class' =&gt; 't',
                      'is_bool' =&gt; true,
                      'values' =&gt; array(
                          array(
                              'id' =&gt; 'active_on',
                              'value' =&gt; 1,
                              'label' =&gt; $this-&gt;l('Enabled')
                          ),
                          array(
                              'id' =&gt; 'active_off',
                              'value' =&gt; 0,
                              'label' =&gt; $this-&gt;l('Disabled')
                          )
                      ),
                      'desc' =&gt; $this-&gt;l('Only one video can be active at any given time')
                  ),
              )
          );
  
          if (Shop::isFeatureActive())
          {
              $this-&gt;fields_form['input'][] = array(
                  'type' =&gt; 'shop',
                  'label' =&gt; $this-&gt;l('Shop association:'),
                  'name' =&gt; 'checkBoxShopAsso',
              );
          }
  
          $this-&gt;fields_form['submit'] = array(
              'title' =&gt; $this-&gt;l('   Save   '),
              'class' =&gt; 'button'
          );
  
          if (!($obj = $this-&gt;loadObject(true)))
              return;
  
          return parent::renderForm();
      }
    }
  </code></pre>
  
  <p>One other thing: would it be possible to add a preview of the video inside the backoffice? I tried to echo YouTube's embed code, but it gets inserted even before the header. Is there a clean way of doing this or do I have to use some jQuery trickery? I was basically doing an echo of YT's embed code just before the end of postProcess().</p>
  
  <p>Thanks in advance!</p>