Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving HABTM with extra fields?
    primarykey
    data
    text
    <p>I am trying to save an order, and the products in the order.</p> <p>The order is being saved, but the products are not.</p> <p>I have an <code>orders</code> table and a <code>products</code> table and a <code>orders_products</code> table.</p> <p>In the Order model I set <code>$hasAndBelongsToMany = 'Product';</code></p> <p>on the <code>orders_products</code> table I have a couple extra fields: <code>order_id</code>, <code>product_id</code> plus <code>price</code>, <code>quantity</code> to capture the sale price and quantity sold.</p> <p>I am saving the data via:</p> <blockquote> <p>$this->Order->saveAll($data);</p> </blockquote> <p>Here is what $data is:</p> <pre><code>Array ( [Order] =&gt; Array ( [user_email] =&gt; st@kr.com [billing_first] =&gt; Steve ... //more excluded [total] =&gt; 5000 ) [Product] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 1 [price] =&gt; 5000.00 [quantity] =&gt; 1 ) ) ) </code></pre> <p>The order gets saved to the order table but nothing is getting saved to the orders_products table. I am expected the orders_products table to save <code>[new_order_id], 1, 5000.00, 1</code></p> <p>I do get this notice:</p> <pre><code>Notice (8): Undefined index: id [CORE/cake/libs/model/model.php, line 1391] Model::__saveMulti() - CORE/cake/libs/model/model.php, line 1391 Model::save() - CORE/cake/libs/model/model.php, line 1355 Model::__save() - CORE/cake/libs/model/model.php, line 1778 Model::saveAll() - CORE/cake/libs/model/model.php, line 1673 CartsController::saveOrder() - APP/controllers/carts_controller.php, line 128 CartsController::checkout() - APP/controllers/carts_controller.php, line 172 Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204 Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171 [main] - APP/webroot/index.php, line 83 </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload