mysql - Prestashop: how to define multiple primary keys with ObjectModel -


I am defining new entities while increasing the object model. I have a table with two such primary keys:

  create table `ec_product_order_attachment` (` id_product` int (10) unsigned tap, `id_order_attachment` int (10) unsigned zero, Primary key (`id_product`,` id_order_attachment`) engine = InnoDB default charge = UTF8;  

It seems, I can not define a table with 2 primary keys in the object model.

Do you know any way to do this?

Update (Solved)

User PrestaShop-Developer Com gave me a good suggestion. I resumed the Order_Attachment custom unit class, and it's working just fine. So just for documenting, I copy-paste my finished class. Just to say, I have created this class for a custom module that adds a tab to the Admin Edit product page, so that the ability to save special attachments can be added that orders will be sent with complete mail. That's why I need 2 new tables: Order_Actactment and Product_order_actment to link products for special order.

  class order-atchact objectModel {public $ name; Public $ mime; Public $ attachment_type; Public $ id_order_attachment; // validation option Prestashop valid squared public public $ $ definition = array ('table' => 'order_attachment', 'primary' = & gt; id_order_attachment ',' multilang '= & gt; wrong,' field '= Array ('type' = & gt; array ('type' = & gt; self :: TYPE_STRING, 'size' => 128), 'mime' => Gt; self: TYPE_STRING, 'size' => 128), 'attachment_type' = & gt; array ('type' = & gt; self :: TYPE_STRING, 'size' => 128))) ; // Specific Products Get Current Order Attachments for Public Fixed Work Get_product_order_attachments ($ id_product = false) {$ id_p = ($ id_product)? $ Id_product: Tools :: getValue ('id_product'); $ Db = db :: getInstance (); $ Sql ​​= 'SELECT * FROM' from _DB_PREFIX_ 'Ordr_atacment Oaanar join' _DB_PREFIX_ 'Product_order_attachment poa ON oa.id_order_attachment = poa.id_order_attachment WHERE poa.id_product ='. $ Id_p; Return $ db- & gt; Executed S ($ sql); } Public Function Save ($ null_values ​​= false, $ autodate = true) {$ result1 = parent :: save (); $ Result2 = DB :: getInstance () - & gt; insert ( 'product_order_attachment', array ( 'id_product' = & gt; Tools :: getValue (= 'id_product'), 'id_order_attachment' & gt; $ this- & gt; ID); return ($ result1 & amp; $ result2 );} delete public function ($ id_product = false) {$ id_p = ($ id_product)? $ Id_product: tools :: destroy getValue ( 'id_product'); // append attached file if (file_exists (_PS_UPLOAD_DIR_. $ This - & gt; name)) unlink (_PS_UPLOAD_DIR_. $ This- & gt; name); parent :: remove (); dB :: getInstance () - & gt; Delete ( 'product_order_attachment', 'id_product ='. $ Id_p. 'And id_order_attachment ='. $ This-> ID);}} // END class 

Multi-column key There is no way to define this by PrestaShop ObjectModel Definition.

  1. Within your order matte object model (if you have it)
  2. object Modols should be a stand-alone entities.

    product Objektmodel (using override necessary methods adding)

  3. you can not ProductOrderAttachment class (object Moodel) and the static methods You can.

However, if you have an order attachment unit, 1) the best way if you do not have it, then you might consider adding it, because it is like "standalone unit" Looks.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -